1d2912cb1SThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-only */ 2c8b75bcaSEric Anholt /* 3c8b75bcaSEric Anholt * Copyright (C) 2015 Broadcom 4c8b75bcaSEric Anholt */ 56a88752cSMaxime Ripard #ifndef _VC4_DRV_H_ 66a88752cSMaxime Ripard #define _VC4_DRV_H_ 7c8b75bcaSEric Anholt 8fd6d6d80SSam Ravnborg #include <linux/delay.h> 973289afeSVille Syrjälä #include <linux/of.h> 10fd6d6d80SSam Ravnborg #include <linux/refcount.h> 11fd6d6d80SSam Ravnborg #include <linux/uaccess.h> 12fd6d6d80SSam Ravnborg 13fd6d6d80SSam Ravnborg #include <drm/drm_atomic.h> 14fd6d6d80SSam Ravnborg #include <drm/drm_debugfs.h> 15fd6d6d80SSam Ravnborg #include <drm/drm_device.h> 169338203cSLaurent Pinchart #include <drm/drm_encoder.h> 174a83c26aSDanilo Krummrich #include <drm/drm_gem_dma_helper.h> 181c80be48SMaxime Ripard #include <drm/drm_managed.h> 19fd6d6d80SSam Ravnborg #include <drm/drm_mm.h> 20fd6d6d80SSam Ravnborg #include <drm/drm_modeset_lock.h> 219338203cSLaurent Pinchart 22da43ff04SMaxime Ripard #include <kunit/test-bug.h> 23da43ff04SMaxime Ripard 2465101d8cSBoris Brezillon #include "uapi/drm/vc4_drm.h" 2565101d8cSBoris Brezillon 26fd6d6d80SSam Ravnborg struct drm_device; 27fd6d6d80SSam Ravnborg struct drm_gem_object; 28fd6d6d80SSam Ravnborg 29f759f5b5SMaxime Ripard extern const struct drm_driver vc4_drm_driver; 30f759f5b5SMaxime Ripard extern const struct drm_driver vc5_drm_driver; 31f759f5b5SMaxime Ripard 32f3099462SEric Anholt /* Don't forget to update vc4_bo.c: bo_type_names[] when adding to 33f3099462SEric Anholt * this. 34f3099462SEric Anholt */ 35f3099462SEric Anholt enum vc4_kernel_bo_type { 36f3099462SEric Anholt /* Any kernel allocation (gem_create_object hook) before it 37f3099462SEric Anholt * gets another type set. 38f3099462SEric Anholt */ 39f3099462SEric Anholt VC4_BO_TYPE_KERNEL, 40f3099462SEric Anholt VC4_BO_TYPE_V3D, 41f3099462SEric Anholt VC4_BO_TYPE_V3D_SHADER, 42f3099462SEric Anholt VC4_BO_TYPE_DUMB, 43f3099462SEric Anholt VC4_BO_TYPE_BIN, 44f3099462SEric Anholt VC4_BO_TYPE_RCL, 45f3099462SEric Anholt VC4_BO_TYPE_BCL, 46f3099462SEric Anholt VC4_BO_TYPE_KERNEL_CACHE, 47f3099462SEric Anholt VC4_BO_TYPE_COUNT 48f3099462SEric Anholt }; 49f3099462SEric Anholt 5065101d8cSBoris Brezillon /* Performance monitor object. The perform lifetime is controlled by userspace 5165101d8cSBoris Brezillon * using perfmon related ioctls. A perfmon can be attached to a submit_cl 5265101d8cSBoris Brezillon * request, and when this is the case, HW perf counters will be activated just 5365101d8cSBoris Brezillon * before the submit_cl is submitted to the GPU and disabled when the job is 5465101d8cSBoris Brezillon * done. This way, only events related to a specific job will be counted. 5565101d8cSBoris Brezillon */ 5665101d8cSBoris Brezillon struct vc4_perfmon { 5730f8c74cSMaxime Ripard struct vc4_dev *dev; 5830f8c74cSMaxime Ripard 5965101d8cSBoris Brezillon /* Tracks the number of users of the perfmon, when this counter reaches 6065101d8cSBoris Brezillon * zero the perfmon is destroyed. 6165101d8cSBoris Brezillon */ 6265101d8cSBoris Brezillon refcount_t refcnt; 6365101d8cSBoris Brezillon 6465101d8cSBoris Brezillon /* Number of counters activated in this perfmon instance 6565101d8cSBoris Brezillon * (should be less than DRM_VC4_MAX_PERF_COUNTERS). 6665101d8cSBoris Brezillon */ 6765101d8cSBoris Brezillon u8 ncounters; 6865101d8cSBoris Brezillon 6965101d8cSBoris Brezillon /* Events counted by the HW perf counters. */ 7065101d8cSBoris Brezillon u8 events[DRM_VC4_MAX_PERF_COUNTERS]; 7165101d8cSBoris Brezillon 7265101d8cSBoris Brezillon /* Storage for counter values. Counters are incremented by the HW 7365101d8cSBoris Brezillon * perf counter values every time the perfmon is attached to a GPU job. 7465101d8cSBoris Brezillon * This way, perfmon users don't have to retrieve the results after 7565101d8cSBoris Brezillon * each job if they want to track events covering several submissions. 7665101d8cSBoris Brezillon * Note that counter values can't be reset, but you can fake a reset by 7765101d8cSBoris Brezillon * destroying the perfmon and creating a new one. 7865101d8cSBoris Brezillon */ 795b2adbddSGustavo A. R. Silva u64 counters[]; 8065101d8cSBoris Brezillon }; 8165101d8cSBoris Brezillon 82c8b75bcaSEric Anholt struct vc4_dev { 8384d7d472SMaxime Ripard struct drm_device base; 846cf61bf4SMaxime Ripard struct device *dev; 85c8b75bcaSEric Anholt 861cbc91ebSMaxime Ripard bool is_vc5; 871cbc91ebSMaxime Ripard 885226711eSThomas Zimmermann unsigned int irq; 895226711eSThomas Zimmermann 90c8b75bcaSEric Anholt struct vc4_hvs *hvs; 91d3f5168aSEric Anholt struct vc4_v3d *v3d; 9248666d56SDerek Foreman 9321461365SEric Anholt struct vc4_hang_state *hang_state; 9421461365SEric Anholt 95c826a6e1SEric Anholt /* The kernel-space BO cache. Tracks buffers that have been 96c826a6e1SEric Anholt * unreferenced by all other users (refcounts of 0!) but not 97c826a6e1SEric Anholt * yet freed, so we can do cheap allocations. 98c826a6e1SEric Anholt */ 99c826a6e1SEric Anholt struct vc4_bo_cache { 100c826a6e1SEric Anholt /* Array of list heads for entries in the BO cache, 101c826a6e1SEric Anholt * based on number of pages, so we can do O(1) lookups 102c826a6e1SEric Anholt * in the cache when allocating. 103c826a6e1SEric Anholt */ 104c826a6e1SEric Anholt struct list_head *size_list; 105c826a6e1SEric Anholt uint32_t size_list_size; 106c826a6e1SEric Anholt 107c826a6e1SEric Anholt /* List of all BOs in the cache, ordered by age, so we 108c826a6e1SEric Anholt * can do O(1) lookups when trying to free old 109c826a6e1SEric Anholt * buffers. 110c826a6e1SEric Anholt */ 111c826a6e1SEric Anholt struct list_head time_list; 112c826a6e1SEric Anholt struct work_struct time_work; 113c826a6e1SEric Anholt struct timer_list time_timer; 114c826a6e1SEric Anholt } bo_cache; 115c826a6e1SEric Anholt 116f3099462SEric Anholt u32 num_labels; 117f3099462SEric Anholt struct vc4_label { 118f3099462SEric Anholt const char *name; 119c826a6e1SEric Anholt u32 num_allocated; 120c826a6e1SEric Anholt u32 size_allocated; 121f3099462SEric Anholt } *bo_labels; 122c826a6e1SEric Anholt 123f3099462SEric Anholt /* Protects bo_cache and bo_labels. */ 124c826a6e1SEric Anholt struct mutex bo_lock; 125d5b1a78aSEric Anholt 126b9f19259SBoris Brezillon /* Purgeable BO pool. All BOs in this pool can have their memory 127b9f19259SBoris Brezillon * reclaimed if the driver is unable to allocate new BOs. We also 128b9f19259SBoris Brezillon * keep stats related to the purge mechanism here. 129b9f19259SBoris Brezillon */ 130b9f19259SBoris Brezillon struct { 131b9f19259SBoris Brezillon struct list_head list; 132b9f19259SBoris Brezillon unsigned int num; 133b9f19259SBoris Brezillon size_t size; 134b9f19259SBoris Brezillon unsigned int purged_num; 135b9f19259SBoris Brezillon size_t purged_size; 136b9f19259SBoris Brezillon struct mutex lock; 137b9f19259SBoris Brezillon } purgeable; 138b9f19259SBoris Brezillon 139cdec4d36SEric Anholt uint64_t dma_fence_context; 140cdec4d36SEric Anholt 141ca26d28bSVarad Gautam /* Sequence number for the last job queued in bin_job_list. 142d5b1a78aSEric Anholt * Starts at 0 (no jobs emitted). 143d5b1a78aSEric Anholt */ 144d5b1a78aSEric Anholt uint64_t emit_seqno; 145d5b1a78aSEric Anholt 146d5b1a78aSEric Anholt /* Sequence number for the last completed job on the GPU. 147d5b1a78aSEric Anholt * Starts at 0 (no jobs completed). 148d5b1a78aSEric Anholt */ 149d5b1a78aSEric Anholt uint64_t finished_seqno; 150d5b1a78aSEric Anholt 151ca26d28bSVarad Gautam /* List of all struct vc4_exec_info for jobs to be executed in 152ca26d28bSVarad Gautam * the binner. The first job in the list is the one currently 153ca26d28bSVarad Gautam * programmed into ct0ca for execution. 154d5b1a78aSEric Anholt */ 155ca26d28bSVarad Gautam struct list_head bin_job_list; 156ca26d28bSVarad Gautam 157ca26d28bSVarad Gautam /* List of all struct vc4_exec_info for jobs that have 158ca26d28bSVarad Gautam * completed binning and are ready for rendering. The first 159ca26d28bSVarad Gautam * job in the list is the one currently programmed into ct1ca 160ca26d28bSVarad Gautam * for execution. 161ca26d28bSVarad Gautam */ 162ca26d28bSVarad Gautam struct list_head render_job_list; 163ca26d28bSVarad Gautam 164d5b1a78aSEric Anholt /* List of the finished vc4_exec_infos waiting to be freed by 165d5b1a78aSEric Anholt * job_done_work. 166d5b1a78aSEric Anholt */ 167d5b1a78aSEric Anholt struct list_head job_done_list; 168d5b1a78aSEric Anholt /* Spinlock used to synchronize the job_list and seqno 169d5b1a78aSEric Anholt * accesses between the IRQ handler and GEM ioctls. 170d5b1a78aSEric Anholt */ 171d5b1a78aSEric Anholt spinlock_t job_lock; 172d5b1a78aSEric Anholt wait_queue_head_t job_wait_queue; 173d5b1a78aSEric Anholt struct work_struct job_done_work; 174d5b1a78aSEric Anholt 17565101d8cSBoris Brezillon /* Used to track the active perfmon if any. Access to this field is 17665101d8cSBoris Brezillon * protected by job_lock. 17765101d8cSBoris Brezillon */ 17865101d8cSBoris Brezillon struct vc4_perfmon *active_perfmon; 17965101d8cSBoris Brezillon 180b501baccSEric Anholt /* List of struct vc4_seqno_cb for callbacks to be made from a 181b501baccSEric Anholt * workqueue when the given seqno is passed. 182b501baccSEric Anholt */ 183b501baccSEric Anholt struct list_head seqno_cb_list; 184b501baccSEric Anholt 185553c942fSEric Anholt /* The memory used for storing binner tile alloc, tile state, 186553c942fSEric Anholt * and overflow memory allocations. This is freed when V3D 187553c942fSEric Anholt * powers down. 188d5b1a78aSEric Anholt */ 189553c942fSEric Anholt struct vc4_bo *bin_bo; 190553c942fSEric Anholt 191553c942fSEric Anholt /* Size of blocks allocated within bin_bo. */ 192553c942fSEric Anholt uint32_t bin_alloc_size; 193553c942fSEric Anholt 194553c942fSEric Anholt /* Bitmask of the bin_alloc_size chunks in bin_bo that are 195553c942fSEric Anholt * used. 196553c942fSEric Anholt */ 197553c942fSEric Anholt uint32_t bin_alloc_used; 198553c942fSEric Anholt 199553c942fSEric Anholt /* Bitmask of the current bin_alloc used for overflow memory. */ 200553c942fSEric Anholt uint32_t bin_alloc_overflow; 201553c942fSEric Anholt 202531a1b62SBoris Brezillon /* Incremented when an underrun error happened after an atomic commit. 203531a1b62SBoris Brezillon * This is particularly useful to detect when a specific modeset is too 204531a1b62SBoris Brezillon * demanding in term of memory or HVS bandwidth which is hard to guess 205531a1b62SBoris Brezillon * at atomic check time. 206531a1b62SBoris Brezillon */ 207531a1b62SBoris Brezillon atomic_t underrun; 208531a1b62SBoris Brezillon 209d5b1a78aSEric Anholt struct work_struct overflow_mem_work; 210d5b1a78aSEric Anholt 21136cb6253SEric Anholt int power_refcount; 21236cb6253SEric Anholt 2136b5c029dSPaul Kocialkowski /* Set to true when the load tracker is active. */ 2146b5c029dSPaul Kocialkowski bool load_tracker_enabled; 2156b5c029dSPaul Kocialkowski 21636cb6253SEric Anholt /* Mutex controlling the power refcount. */ 21736cb6253SEric Anholt struct mutex power_lock; 21836cb6253SEric Anholt 219d5b1a78aSEric Anholt struct { 220d5b1a78aSEric Anholt struct timer_list timer; 221d5b1a78aSEric Anholt struct work_struct reset_work; 222d5b1a78aSEric Anholt } hangcheck; 223d5b1a78aSEric Anholt 224766cc6b1SStefan Schake struct drm_modeset_lock ctm_state_lock; 225766cc6b1SStefan Schake struct drm_private_obj ctm_manager; 226f2df84e0SMaxime Ripard struct drm_private_obj hvs_channels; 2274686da83SBoris Brezillon struct drm_private_obj load_tracker; 228c9be804cSEric Anholt 22935c8b4b2SPaul Kocialkowski /* Mutex for binner bo allocation. */ 23035c8b4b2SPaul Kocialkowski struct mutex bin_bo_lock; 23135c8b4b2SPaul Kocialkowski /* Reference count for our binner bo. */ 23235c8b4b2SPaul Kocialkowski struct kref bin_bo_kref; 233c8b75bcaSEric Anholt }; 234c8b75bcaSEric Anholt 235*5a46e490SMaxime Ripard #define to_vc4_dev(_dev) \ 236*5a46e490SMaxime Ripard container_of_const(_dev, struct vc4_dev, base) 237c8b75bcaSEric Anholt 238c8b75bcaSEric Anholt struct vc4_bo { 2394a83c26aSDanilo Krummrich struct drm_gem_dma_object base; 240c826a6e1SEric Anholt 2417edabee0SEric Anholt /* seqno of the last job to render using this BO. */ 242d5b1a78aSEric Anholt uint64_t seqno; 243d5b1a78aSEric Anholt 2447edabee0SEric Anholt /* seqno of the last job to use the RCL to write to this BO. 2457edabee0SEric Anholt * 2467edabee0SEric Anholt * Note that this doesn't include binner overflow memory 2477edabee0SEric Anholt * writes. 2487edabee0SEric Anholt */ 2497edabee0SEric Anholt uint64_t write_seqno; 2507edabee0SEric Anholt 25183753117SEric Anholt bool t_format; 25283753117SEric Anholt 253c826a6e1SEric Anholt /* List entry for the BO's position in either 254c826a6e1SEric Anholt * vc4_exec_info->unref_list or vc4_dev->bo_cache.time_list 255c826a6e1SEric Anholt */ 256c826a6e1SEric Anholt struct list_head unref_head; 257c826a6e1SEric Anholt 258c826a6e1SEric Anholt /* Time in jiffies when the BO was put in vc4->bo_cache. */ 259c826a6e1SEric Anholt unsigned long free_time; 260c826a6e1SEric Anholt 261c826a6e1SEric Anholt /* List entry for the BO's position in vc4_dev->bo_cache.size_list */ 262c826a6e1SEric Anholt struct list_head size_head; 263463873d5SEric Anholt 264463873d5SEric Anholt /* Struct for shader validation state, if created by 265463873d5SEric Anholt * DRM_IOCTL_VC4_CREATE_SHADER_BO. 266463873d5SEric Anholt */ 267463873d5SEric Anholt struct vc4_validated_shader_info *validated_shader; 268cdec4d36SEric Anholt 269f3099462SEric Anholt /* One of enum vc4_kernel_bo_type, or VC4_BO_TYPE_COUNT + i 270f3099462SEric Anholt * for user-allocated labels. 271f3099462SEric Anholt */ 272f3099462SEric Anholt int label; 273b9f19259SBoris Brezillon 274b9f19259SBoris Brezillon /* Count the number of active users. This is needed to determine 275b9f19259SBoris Brezillon * whether we can move the BO to the purgeable list or not (when the BO 276b9f19259SBoris Brezillon * is used by the GPU or the display engine we can't purge it). 277b9f19259SBoris Brezillon */ 278b9f19259SBoris Brezillon refcount_t usecnt; 279b9f19259SBoris Brezillon 280b9f19259SBoris Brezillon /* Store purgeable/purged state here */ 281b9f19259SBoris Brezillon u32 madv; 282b9f19259SBoris Brezillon struct mutex madv_lock; 283c8b75bcaSEric Anholt }; 284c8b75bcaSEric Anholt 285*5a46e490SMaxime Ripard #define to_vc4_bo(_bo) \ 286*5a46e490SMaxime Ripard container_of_const(to_drm_gem_dma_obj(_bo), struct vc4_bo, base) 287c8b75bcaSEric Anholt 288cdec4d36SEric Anholt struct vc4_fence { 289cdec4d36SEric Anholt struct dma_fence base; 290cdec4d36SEric Anholt struct drm_device *dev; 291cdec4d36SEric Anholt /* vc4 seqno for signaled() test */ 292cdec4d36SEric Anholt uint64_t seqno; 293cdec4d36SEric Anholt }; 294cdec4d36SEric Anholt 295*5a46e490SMaxime Ripard #define to_vc4_fence(_fence) \ 296*5a46e490SMaxime Ripard container_of_const(_fence, struct vc4_fence, base) 297cdec4d36SEric Anholt 298b501baccSEric Anholt struct vc4_seqno_cb { 299b501baccSEric Anholt struct work_struct work; 300b501baccSEric Anholt uint64_t seqno; 301b501baccSEric Anholt void (*func)(struct vc4_seqno_cb *cb); 302b501baccSEric Anholt }; 303b501baccSEric Anholt 304d3f5168aSEric Anholt struct vc4_v3d { 305001bdb55SEric Anholt struct vc4_dev *vc4; 306d3f5168aSEric Anholt struct platform_device *pdev; 307d3f5168aSEric Anholt void __iomem *regs; 308b72a2816SEric Anholt struct clk *clk; 3093051719aSEric Anholt struct debugfs_regset32 regset; 310d3f5168aSEric Anholt }; 311d3f5168aSEric Anholt 312c8b75bcaSEric Anholt struct vc4_hvs { 3131cbc91ebSMaxime Ripard struct vc4_dev *vc4; 314c8b75bcaSEric Anholt struct platform_device *pdev; 315c8b75bcaSEric Anholt void __iomem *regs; 316d8dbf44fSEric Anholt u32 __iomem *dlist; 317d8dbf44fSEric Anholt 318d7d96c00SMaxime Ripard struct clk *core_clk; 319d7d96c00SMaxime Ripard 3202a001ca0SMaxime Ripard unsigned long max_core_rate; 3212a001ca0SMaxime Ripard 322d8dbf44fSEric Anholt /* Memory manager for CRTCs to allocate space in the display 323d8dbf44fSEric Anholt * list. Units are dwords. 324d8dbf44fSEric Anholt */ 325d8dbf44fSEric Anholt struct drm_mm dlist_mm; 32621af94cfSEric Anholt /* Memory manager for the LBM memory used by HVS scaling. */ 32721af94cfSEric Anholt struct drm_mm lbm_mm; 328d8dbf44fSEric Anholt spinlock_t mm_lock; 32921af94cfSEric Anholt 33021af94cfSEric Anholt struct drm_mm_node mitchell_netravali_filter; 331c54619b0SDave Stevenson 3323051719aSEric Anholt struct debugfs_regset32 regset; 3332a001ca0SMaxime Ripard 3342a001ca0SMaxime Ripard /* 3352a001ca0SMaxime Ripard * Even if HDMI0 on the RPi4 can output modes requiring a pixel 3362a001ca0SMaxime Ripard * rate higher than 297MHz, it needs some adjustments in the 3372a001ca0SMaxime Ripard * config.txt file to be able to do so and thus won't always be 3382a001ca0SMaxime Ripard * available. 3392a001ca0SMaxime Ripard */ 3402a001ca0SMaxime Ripard bool vc5_hdmi_enable_hdmi_20; 341f09e172dSDom Cobley 342f09e172dSDom Cobley /* 343f09e172dSDom Cobley * 4096x2160@60 requires a core overclock to work, so register 344f09e172dSDom Cobley * whether that is sufficient. 345f09e172dSDom Cobley */ 346f09e172dSDom Cobley bool vc5_hdmi_enable_4096by2160; 347c8b75bcaSEric Anholt }; 348c8b75bcaSEric Anholt 3493c5cb5ecSMaxime Ripard #define HVS_NUM_CHANNELS 3 3503c5cb5ecSMaxime Ripard 3513c5cb5ecSMaxime Ripard struct vc4_hvs_state { 3523c5cb5ecSMaxime Ripard struct drm_private_state base; 3533c5cb5ecSMaxime Ripard unsigned long core_clock_rate; 3543c5cb5ecSMaxime Ripard 3553c5cb5ecSMaxime Ripard struct { 3563c5cb5ecSMaxime Ripard unsigned in_use: 1; 3573c5cb5ecSMaxime Ripard unsigned long fifo_load; 3583c5cb5ecSMaxime Ripard struct drm_crtc_commit *pending_commit; 3593c5cb5ecSMaxime Ripard } fifo_state[HVS_NUM_CHANNELS]; 3603c5cb5ecSMaxime Ripard }; 3613c5cb5ecSMaxime Ripard 362*5a46e490SMaxime Ripard #define to_vc4_hvs_state(_state) \ 363*5a46e490SMaxime Ripard container_of_const(_state, struct vc4_hvs_state, base) 3643c5cb5ecSMaxime Ripard 3653c5cb5ecSMaxime Ripard struct vc4_hvs_state *vc4_hvs_get_global_state(struct drm_atomic_state *state); 3663c5cb5ecSMaxime Ripard struct vc4_hvs_state *vc4_hvs_get_old_global_state(const struct drm_atomic_state *state); 3673c5cb5ecSMaxime Ripard struct vc4_hvs_state *vc4_hvs_get_new_global_state(const struct drm_atomic_state *state); 3683c5cb5ecSMaxime Ripard 369c8b75bcaSEric Anholt struct vc4_plane { 370c8b75bcaSEric Anholt struct drm_plane base; 371c8b75bcaSEric Anholt }; 372c8b75bcaSEric Anholt 373*5a46e490SMaxime Ripard #define to_vc4_plane(_plane) \ 374*5a46e490SMaxime Ripard container_of_const(_plane, struct vc4_plane, base) 375c8b75bcaSEric Anholt 37682364698SStefan Schake enum vc4_scaling_mode { 37782364698SStefan Schake VC4_SCALING_NONE, 37882364698SStefan Schake VC4_SCALING_TPZ, 37982364698SStefan Schake VC4_SCALING_PPF, 38082364698SStefan Schake }; 38182364698SStefan Schake 38282364698SStefan Schake struct vc4_plane_state { 38382364698SStefan Schake struct drm_plane_state base; 38482364698SStefan Schake /* System memory copy of the display list for this element, computed 38582364698SStefan Schake * at atomic_check time. 38682364698SStefan Schake */ 38782364698SStefan Schake u32 *dlist; 38882364698SStefan Schake u32 dlist_size; /* Number of dwords allocated for the display list */ 38982364698SStefan Schake u32 dlist_count; /* Number of used dwords in the display list. */ 39082364698SStefan Schake 39182364698SStefan Schake /* Offset in the dlist to various words, for pageflip or 39282364698SStefan Schake * cursor updates. 39382364698SStefan Schake */ 39482364698SStefan Schake u32 pos0_offset; 39582364698SStefan Schake u32 pos2_offset; 39682364698SStefan Schake u32 ptr0_offset; 3970a038c1cSBoris Brezillon u32 lbm_offset; 39882364698SStefan Schake 39982364698SStefan Schake /* Offset where the plane's dlist was last stored in the 40082364698SStefan Schake * hardware at vc4_crtc_atomic_flush() time. 40182364698SStefan Schake */ 40282364698SStefan Schake u32 __iomem *hw_dlist; 40382364698SStefan Schake 40482364698SStefan Schake /* Clipped coordinates of the plane on the display. */ 40582364698SStefan Schake int crtc_x, crtc_y, crtc_w, crtc_h; 40682364698SStefan Schake /* Clipped area being scanned from in the FB. */ 40782364698SStefan Schake u32 src_x, src_y; 40882364698SStefan Schake 40982364698SStefan Schake u32 src_w[2], src_h[2]; 41082364698SStefan Schake 41182364698SStefan Schake /* Scaling selection for the RGB/Y plane and the Cb/Cr planes. */ 41282364698SStefan Schake enum vc4_scaling_mode x_scaling[2], y_scaling[2]; 41382364698SStefan Schake bool is_unity; 41482364698SStefan Schake bool is_yuv; 41582364698SStefan Schake 41682364698SStefan Schake /* Offset to start scanning out from the start of the plane's 41782364698SStefan Schake * BO. 41882364698SStefan Schake */ 41982364698SStefan Schake u32 offsets[3]; 42082364698SStefan Schake 42182364698SStefan Schake /* Our allocation in LBM for temporary storage during scaling. */ 42282364698SStefan Schake struct drm_mm_node lbm; 42382364698SStefan Schake 42482364698SStefan Schake /* Set when the plane has per-pixel alpha content or does not cover 42582364698SStefan Schake * the entire screen. This is a hint to the CRTC that it might need 42682364698SStefan Schake * to enable background color fill. 42782364698SStefan Schake */ 42882364698SStefan Schake bool needs_bg_fill; 4298d938449SBoris Brezillon 4308d938449SBoris Brezillon /* Mark the dlist as initialized. Useful to avoid initializing it twice 4318d938449SBoris Brezillon * when async update is not possible. 4328d938449SBoris Brezillon */ 4338d938449SBoris Brezillon bool dlist_initialized; 4344686da83SBoris Brezillon 4354686da83SBoris Brezillon /* Load of this plane on the HVS block. The load is expressed in HVS 4364686da83SBoris Brezillon * cycles/sec. 4374686da83SBoris Brezillon */ 4384686da83SBoris Brezillon u64 hvs_load; 4394686da83SBoris Brezillon 4404686da83SBoris Brezillon /* Memory bandwidth needed for this plane. This is expressed in 4414686da83SBoris Brezillon * bytes/sec. 4424686da83SBoris Brezillon */ 4434686da83SBoris Brezillon u64 membus_load; 44482364698SStefan Schake }; 44582364698SStefan Schake 446*5a46e490SMaxime Ripard #define to_vc4_plane_state(_state) \ 447*5a46e490SMaxime Ripard container_of_const(_state, struct vc4_plane_state, base) 44882364698SStefan Schake 449c8b75bcaSEric Anholt enum vc4_encoder_type { 450ab8df60eSBoris Brezillon VC4_ENCODER_TYPE_NONE, 451ed024b22SMaxime Ripard VC4_ENCODER_TYPE_HDMI0, 452aa2fd1caSMaxime Ripard VC4_ENCODER_TYPE_HDMI1, 453c8b75bcaSEric Anholt VC4_ENCODER_TYPE_VEC, 454c8b75bcaSEric Anholt VC4_ENCODER_TYPE_DSI0, 455c8b75bcaSEric Anholt VC4_ENCODER_TYPE_DSI1, 456c8b75bcaSEric Anholt VC4_ENCODER_TYPE_SMI, 457c8b75bcaSEric Anholt VC4_ENCODER_TYPE_DPI, 458b998eb4fSMaxime Ripard VC4_ENCODER_TYPE_TXP, 459c8b75bcaSEric Anholt }; 460c8b75bcaSEric Anholt 461c8b75bcaSEric Anholt struct vc4_encoder { 462c8b75bcaSEric Anholt struct drm_encoder base; 463c8b75bcaSEric Anholt enum vc4_encoder_type type; 464c8b75bcaSEric Anholt u32 clock_select; 465792c3132SMaxime Ripard 4668d914746SMaxime Ripard void (*pre_crtc_configure)(struct drm_encoder *encoder, struct drm_atomic_state *state); 4678d914746SMaxime Ripard void (*pre_crtc_enable)(struct drm_encoder *encoder, struct drm_atomic_state *state); 4688d914746SMaxime Ripard void (*post_crtc_enable)(struct drm_encoder *encoder, struct drm_atomic_state *state); 469792c3132SMaxime Ripard 4708d914746SMaxime Ripard void (*post_crtc_disable)(struct drm_encoder *encoder, struct drm_atomic_state *state); 4718d914746SMaxime Ripard void (*post_crtc_powerdown)(struct drm_encoder *encoder, struct drm_atomic_state *state); 472c8b75bcaSEric Anholt }; 473c8b75bcaSEric Anholt 474*5a46e490SMaxime Ripard #define to_vc4_encoder(_encoder) \ 475*5a46e490SMaxime Ripard container_of_const(_encoder, struct vc4_encoder, base) 476c8b75bcaSEric Anholt 4770656ce12SMaxime Ripard static inline 4780656ce12SMaxime Ripard struct drm_encoder *vc4_find_encoder_by_type(struct drm_device *drm, 4790656ce12SMaxime Ripard enum vc4_encoder_type type) 4800656ce12SMaxime Ripard { 4810656ce12SMaxime Ripard struct drm_encoder *encoder; 4820656ce12SMaxime Ripard 4830656ce12SMaxime Ripard drm_for_each_encoder(encoder, drm) { 4840656ce12SMaxime Ripard struct vc4_encoder *vc4_encoder = to_vc4_encoder(encoder); 4850656ce12SMaxime Ripard 4860656ce12SMaxime Ripard if (vc4_encoder->type == type) 4870656ce12SMaxime Ripard return encoder; 4880656ce12SMaxime Ripard } 4890656ce12SMaxime Ripard 4900656ce12SMaxime Ripard return NULL; 4910656ce12SMaxime Ripard } 4920656ce12SMaxime Ripard 49379271807SStefan Schake struct vc4_crtc_data { 4949a49bf09SMaxime Ripard const char *name; 4959a49bf09SMaxime Ripard 4966bad4774SMaxime Ripard const char *debugfs_name; 4976bad4774SMaxime Ripard 49887ebcd42SMaxime Ripard /* Bitmask of channels (FIFOs) of the HVS that the output can source from */ 49987ebcd42SMaxime Ripard unsigned int hvs_available_channels; 50087ebcd42SMaxime Ripard 5018ebb2cf0SMaxime Ripard /* Which output of the HVS this pixelvalve sources from. */ 5028ebb2cf0SMaxime Ripard int hvs_output; 5035a20ff8bSMaxime Ripard }; 5045a20ff8bSMaxime Ripard 505f759f5b5SMaxime Ripard extern const struct vc4_crtc_data vc4_txp_crtc_data; 506f759f5b5SMaxime Ripard 5075a20ff8bSMaxime Ripard struct vc4_pv_data { 5085a20ff8bSMaxime Ripard struct vc4_crtc_data base; 50979271807SStefan Schake 510649abf2fSMaxime Ripard /* Depth of the PixelValve FIFO in bytes */ 511649abf2fSMaxime Ripard unsigned int fifo_depth; 512649abf2fSMaxime Ripard 513644df22fSMaxime Ripard /* Number of pixels output per clock period */ 514644df22fSMaxime Ripard u8 pixels_per_clock; 515644df22fSMaxime Ripard 51679271807SStefan Schake enum vc4_encoder_type encoder_types[4]; 51779271807SStefan Schake }; 51879271807SStefan Schake 519f759f5b5SMaxime Ripard extern const struct vc4_pv_data bcm2835_pv0_data; 520f759f5b5SMaxime Ripard extern const struct vc4_pv_data bcm2835_pv1_data; 521f759f5b5SMaxime Ripard extern const struct vc4_pv_data bcm2835_pv2_data; 522f759f5b5SMaxime Ripard extern const struct vc4_pv_data bcm2711_pv0_data; 523f759f5b5SMaxime Ripard extern const struct vc4_pv_data bcm2711_pv1_data; 524f759f5b5SMaxime Ripard extern const struct vc4_pv_data bcm2711_pv2_data; 525f759f5b5SMaxime Ripard extern const struct vc4_pv_data bcm2711_pv3_data; 526f759f5b5SMaxime Ripard extern const struct vc4_pv_data bcm2711_pv4_data; 527f759f5b5SMaxime Ripard 52879271807SStefan Schake struct vc4_crtc { 52979271807SStefan Schake struct drm_crtc base; 5303051719aSEric Anholt struct platform_device *pdev; 53179271807SStefan Schake const struct vc4_crtc_data *data; 53279271807SStefan Schake void __iomem *regs; 53379271807SStefan Schake 53479271807SStefan Schake /* Timestamp at start of vblank irq - unaffected by lock delays. */ 53579271807SStefan Schake ktime_t t_vblank; 53679271807SStefan Schake 53779271807SStefan Schake u8 lut_r[256]; 53879271807SStefan Schake u8 lut_g[256]; 53979271807SStefan Schake u8 lut_b[256]; 54079271807SStefan Schake 54179271807SStefan Schake struct drm_pending_vblank_event *event; 5423051719aSEric Anholt 5433051719aSEric Anholt struct debugfs_regset32 regset; 544a16c6640SMaxime Ripard 545a16c6640SMaxime Ripard /** 546a16c6640SMaxime Ripard * @feeds_txp: True if the CRTC feeds our writeback controller. 547a16c6640SMaxime Ripard */ 548a16c6640SMaxime Ripard bool feeds_txp; 5490c250c15SMaxime Ripard 5500c250c15SMaxime Ripard /** 5510c250c15SMaxime Ripard * @irq_lock: Spinlock protecting the resources shared between 5520c250c15SMaxime Ripard * the atomic code and our vblank handler. 5530c250c15SMaxime Ripard */ 5540c250c15SMaxime Ripard spinlock_t irq_lock; 5550c250c15SMaxime Ripard 5560c250c15SMaxime Ripard /** 5570c250c15SMaxime Ripard * @current_dlist: Start offset of the display list currently 5580c250c15SMaxime Ripard * set in the HVS for that CRTC. Protected by @irq_lock, and 5590c250c15SMaxime Ripard * copied in vc4_hvs_update_dlist() for the CRTC interrupt 5600c250c15SMaxime Ripard * handler to have access to that value. 5610c250c15SMaxime Ripard */ 5620c250c15SMaxime Ripard unsigned int current_dlist; 563eeb6ab46SMaxime Ripard 564eeb6ab46SMaxime Ripard /** 565eeb6ab46SMaxime Ripard * @current_hvs_channel: HVS channel currently assigned to the 566eeb6ab46SMaxime Ripard * CRTC. Protected by @irq_lock, and copied in 567eeb6ab46SMaxime Ripard * vc4_hvs_atomic_begin() for the CRTC interrupt handler to have 568eeb6ab46SMaxime Ripard * access to that value. 569eeb6ab46SMaxime Ripard */ 570eeb6ab46SMaxime Ripard unsigned int current_hvs_channel; 57179271807SStefan Schake }; 57279271807SStefan Schake 573*5a46e490SMaxime Ripard #define to_vc4_crtc(_crtc) \ 574*5a46e490SMaxime Ripard container_of_const(_crtc, struct vc4_crtc, base) 57579271807SStefan Schake 5765a20ff8bSMaxime Ripard static inline const struct vc4_crtc_data * 5775a20ff8bSMaxime Ripard vc4_crtc_to_vc4_crtc_data(const struct vc4_crtc *crtc) 5785a20ff8bSMaxime Ripard { 5795a20ff8bSMaxime Ripard return crtc->data; 5805a20ff8bSMaxime Ripard } 5815a20ff8bSMaxime Ripard 5825a20ff8bSMaxime Ripard static inline const struct vc4_pv_data * 5835a20ff8bSMaxime Ripard vc4_crtc_to_vc4_pv_data(const struct vc4_crtc *crtc) 5845a20ff8bSMaxime Ripard { 5855a20ff8bSMaxime Ripard const struct vc4_crtc_data *data = vc4_crtc_to_vc4_crtc_data(crtc); 5865a20ff8bSMaxime Ripard 587*5a46e490SMaxime Ripard return container_of_const(data, struct vc4_pv_data, base); 5885a20ff8bSMaxime Ripard } 5895a20ff8bSMaxime Ripard 590d0229c36SMaxime Ripard struct drm_encoder *vc4_get_crtc_encoder(struct drm_crtc *crtc, 59194c1adc4SMaxime Ripard struct drm_crtc_state *state); 592d0229c36SMaxime Ripard 593ae44a527SMaxime Ripard struct vc4_crtc_state { 594ae44a527SMaxime Ripard struct drm_crtc_state base; 595ae44a527SMaxime Ripard /* Dlist area for this CRTC configuration. */ 596ae44a527SMaxime Ripard struct drm_mm_node mm; 597ae44a527SMaxime Ripard bool txp_armed; 59887ebcd42SMaxime Ripard unsigned int assigned_channel; 599ae44a527SMaxime Ripard 600ae44a527SMaxime Ripard struct { 601ae44a527SMaxime Ripard unsigned int left; 602ae44a527SMaxime Ripard unsigned int right; 603ae44a527SMaxime Ripard unsigned int top; 604ae44a527SMaxime Ripard unsigned int bottom; 605ae44a527SMaxime Ripard } margins; 6062820526dSMaxime Ripard 60716e10105SMaxime Ripard unsigned long hvs_load; 60816e10105SMaxime Ripard 6092820526dSMaxime Ripard /* Transitional state below, only valid during atomic commits */ 6102820526dSMaxime Ripard bool update_muxing; 611ae44a527SMaxime Ripard }; 612ae44a527SMaxime Ripard 6138ba0b6d1SMaxime Ripard #define VC4_HVS_CHANNEL_DISABLED ((unsigned int)-1) 6148ba0b6d1SMaxime Ripard 615*5a46e490SMaxime Ripard #define to_vc4_crtc_state(_state) \ 616*5a46e490SMaxime Ripard container_of_const(_state, struct vc4_crtc_state, base) 617ae44a527SMaxime Ripard 618da43ff04SMaxime Ripard #define V3D_READ(offset) \ 619da43ff04SMaxime Ripard ({ \ 620da43ff04SMaxime Ripard kunit_fail_current_test("Accessing a register in a unit test!\n"); \ 621da43ff04SMaxime Ripard readl(vc4->v3d->regs + (offset)); \ 622da43ff04SMaxime Ripard }) 623da43ff04SMaxime Ripard 624da43ff04SMaxime Ripard #define V3D_WRITE(offset, val) \ 625da43ff04SMaxime Ripard do { \ 626da43ff04SMaxime Ripard kunit_fail_current_test("Accessing a register in a unit test!\n"); \ 627da43ff04SMaxime Ripard writel(val, vc4->v3d->regs + (offset)); \ 628da43ff04SMaxime Ripard } while (0) 629da43ff04SMaxime Ripard 630da43ff04SMaxime Ripard #define HVS_READ(offset) \ 631da43ff04SMaxime Ripard ({ \ 632da43ff04SMaxime Ripard kunit_fail_current_test("Accessing a register in a unit test!\n"); \ 633da43ff04SMaxime Ripard readl(hvs->regs + (offset)); \ 634da43ff04SMaxime Ripard }) 635da43ff04SMaxime Ripard 636da43ff04SMaxime Ripard #define HVS_WRITE(offset, val) \ 637da43ff04SMaxime Ripard do { \ 638da43ff04SMaxime Ripard kunit_fail_current_test("Accessing a register in a unit test!\n"); \ 639da43ff04SMaxime Ripard writel(val, hvs->regs + (offset)); \ 640da43ff04SMaxime Ripard } while (0) 641c8b75bcaSEric Anholt 6423051719aSEric Anholt #define VC4_REG32(reg) { .name = #reg, .offset = reg } 6433051719aSEric Anholt 644d5b1a78aSEric Anholt struct vc4_exec_info { 64530f8c74cSMaxime Ripard struct vc4_dev *dev; 64630f8c74cSMaxime Ripard 647d5b1a78aSEric Anholt /* Sequence number for this bin/render job. */ 648d5b1a78aSEric Anholt uint64_t seqno; 649d5b1a78aSEric Anholt 6507edabee0SEric Anholt /* Latest write_seqno of any BO that binning depends on. */ 6517edabee0SEric Anholt uint64_t bin_dep_seqno; 6527edabee0SEric Anholt 653cdec4d36SEric Anholt struct dma_fence *fence; 654cdec4d36SEric Anholt 655c4ce60dcSEric Anholt /* Last current addresses the hardware was processing when the 656c4ce60dcSEric Anholt * hangcheck timer checked on us. 657c4ce60dcSEric Anholt */ 658c4ce60dcSEric Anholt uint32_t last_ct0ca, last_ct1ca; 659c4ce60dcSEric Anholt 660d5b1a78aSEric Anholt /* Kernel-space copy of the ioctl arguments */ 661d5b1a78aSEric Anholt struct drm_vc4_submit_cl *args; 662d5b1a78aSEric Anholt 663d5b1a78aSEric Anholt /* This is the array of BOs that were looked up at the start of exec. 664d5b1a78aSEric Anholt * Command validation will use indices into this array. 665d5b1a78aSEric Anholt */ 66647c07e46SMaíra Canal struct drm_gem_object **bo; 667d5b1a78aSEric Anholt uint32_t bo_count; 668d5b1a78aSEric Anholt 6697edabee0SEric Anholt /* List of BOs that are being written by the RCL. Other than 6707edabee0SEric Anholt * the binner temporary storage, this is all the BOs written 6717edabee0SEric Anholt * by the job. 6727edabee0SEric Anholt */ 6734a83c26aSDanilo Krummrich struct drm_gem_dma_object *rcl_write_bo[4]; 6747edabee0SEric Anholt uint32_t rcl_write_bo_count; 6757edabee0SEric Anholt 676d5b1a78aSEric Anholt /* Pointers for our position in vc4->job_list */ 677d5b1a78aSEric Anholt struct list_head head; 678d5b1a78aSEric Anholt 679d5b1a78aSEric Anholt /* List of other BOs used in the job that need to be released 680d5b1a78aSEric Anholt * once the job is complete. 681d5b1a78aSEric Anholt */ 682d5b1a78aSEric Anholt struct list_head unref_list; 683d5b1a78aSEric Anholt 684d5b1a78aSEric Anholt /* Current unvalidated indices into @bo loaded by the non-hardware 685d5b1a78aSEric Anholt * VC4_PACKET_GEM_HANDLES. 686d5b1a78aSEric Anholt */ 687d5b1a78aSEric Anholt uint32_t bo_index[2]; 688d5b1a78aSEric Anholt 689d5b1a78aSEric Anholt /* This is the BO where we store the validated command lists, shader 690d5b1a78aSEric Anholt * records, and uniforms. 691d5b1a78aSEric Anholt */ 6924a83c26aSDanilo Krummrich struct drm_gem_dma_object *exec_bo; 693d5b1a78aSEric Anholt 694d5b1a78aSEric Anholt /** 695d5b1a78aSEric Anholt * This tracks the per-shader-record state (packet 64) that 696d5b1a78aSEric Anholt * determines the length of the shader record and the offset 697d5b1a78aSEric Anholt * it's expected to be found at. It gets read in from the 698d5b1a78aSEric Anholt * command lists. 699d5b1a78aSEric Anholt */ 700d5b1a78aSEric Anholt struct vc4_shader_state { 701d5b1a78aSEric Anholt uint32_t addr; 702d5b1a78aSEric Anholt /* Maximum vertex index referenced by any primitive using this 703d5b1a78aSEric Anholt * shader state. 704d5b1a78aSEric Anholt */ 705d5b1a78aSEric Anholt uint32_t max_index; 706d5b1a78aSEric Anholt } *shader_state; 707d5b1a78aSEric Anholt 708d5b1a78aSEric Anholt /** How many shader states the user declared they were using. */ 709d5b1a78aSEric Anholt uint32_t shader_state_size; 710d5b1a78aSEric Anholt /** How many shader state records the validator has seen. */ 711d5b1a78aSEric Anholt uint32_t shader_state_count; 712d5b1a78aSEric Anholt 713d5b1a78aSEric Anholt bool found_tile_binning_mode_config_packet; 714d5b1a78aSEric Anholt bool found_start_tile_binning_packet; 715d5b1a78aSEric Anholt bool found_increment_semaphore_packet; 716d5b1a78aSEric Anholt bool found_flush; 717d5b1a78aSEric Anholt uint8_t bin_tiles_x, bin_tiles_y; 718553c942fSEric Anholt /* Physical address of the start of the tile alloc array 719553c942fSEric Anholt * (where each tile's binned CL will start) 720553c942fSEric Anholt */ 721d5b1a78aSEric Anholt uint32_t tile_alloc_offset; 722553c942fSEric Anholt /* Bitmask of which binner slots are freed when this job completes. */ 723553c942fSEric Anholt uint32_t bin_slots; 724d5b1a78aSEric Anholt 725d5b1a78aSEric Anholt /** 726d5b1a78aSEric Anholt * Computed addresses pointing into exec_bo where we start the 727d5b1a78aSEric Anholt * bin thread (ct0) and render thread (ct1). 728d5b1a78aSEric Anholt */ 729d5b1a78aSEric Anholt uint32_t ct0ca, ct0ea; 730d5b1a78aSEric Anholt uint32_t ct1ca, ct1ea; 731d5b1a78aSEric Anholt 732d5b1a78aSEric Anholt /* Pointer to the unvalidated bin CL (if present). */ 733d5b1a78aSEric Anholt void *bin_u; 734d5b1a78aSEric Anholt 735d5b1a78aSEric Anholt /* Pointers to the shader recs. These paddr gets incremented as CL 736d5b1a78aSEric Anholt * packets are relocated in validate_gl_shader_state, and the vaddrs 737d5b1a78aSEric Anholt * (u and v) get incremented and size decremented as the shader recs 738d5b1a78aSEric Anholt * themselves are validated. 739d5b1a78aSEric Anholt */ 740d5b1a78aSEric Anholt void *shader_rec_u; 741d5b1a78aSEric Anholt void *shader_rec_v; 742d5b1a78aSEric Anholt uint32_t shader_rec_p; 743d5b1a78aSEric Anholt uint32_t shader_rec_size; 744d5b1a78aSEric Anholt 745d5b1a78aSEric Anholt /* Pointers to the uniform data. These pointers are incremented, and 746d5b1a78aSEric Anholt * size decremented, as each batch of uniforms is uploaded. 747d5b1a78aSEric Anholt */ 748d5b1a78aSEric Anholt void *uniforms_u; 749d5b1a78aSEric Anholt void *uniforms_v; 750d5b1a78aSEric Anholt uint32_t uniforms_p; 751d5b1a78aSEric Anholt uint32_t uniforms_size; 75265101d8cSBoris Brezillon 75365101d8cSBoris Brezillon /* Pointer to a performance monitor object if the user requested it, 75465101d8cSBoris Brezillon * NULL otherwise. 75565101d8cSBoris Brezillon */ 75665101d8cSBoris Brezillon struct vc4_perfmon *perfmon; 75735c8b4b2SPaul Kocialkowski 75835c8b4b2SPaul Kocialkowski /* Whether the exec has taken a reference to the binner BO, which should 75935c8b4b2SPaul Kocialkowski * happen with a VC4_PACKET_TILE_BINNING_MODE_CONFIG packet. 76035c8b4b2SPaul Kocialkowski */ 76135c8b4b2SPaul Kocialkowski bool bin_bo_used; 76265101d8cSBoris Brezillon }; 76365101d8cSBoris Brezillon 76465101d8cSBoris Brezillon /* Per-open file private data. Any driver-specific resource that has to be 76565101d8cSBoris Brezillon * released when the DRM file is closed should be placed here. 76665101d8cSBoris Brezillon */ 76765101d8cSBoris Brezillon struct vc4_file { 76830f8c74cSMaxime Ripard struct vc4_dev *dev; 76930f8c74cSMaxime Ripard 77065101d8cSBoris Brezillon struct { 77165101d8cSBoris Brezillon struct idr idr; 77265101d8cSBoris Brezillon struct mutex lock; 77365101d8cSBoris Brezillon } perfmon; 77435c8b4b2SPaul Kocialkowski 77535c8b4b2SPaul Kocialkowski bool bin_bo_used; 776d5b1a78aSEric Anholt }; 777d5b1a78aSEric Anholt 778d5b1a78aSEric Anholt static inline struct vc4_exec_info * 779ca26d28bSVarad Gautam vc4_first_bin_job(struct vc4_dev *vc4) 780d5b1a78aSEric Anholt { 78157b9f569SMasahiro Yamada return list_first_entry_or_null(&vc4->bin_job_list, 78257b9f569SMasahiro Yamada struct vc4_exec_info, head); 783ca26d28bSVarad Gautam } 784ca26d28bSVarad Gautam 785ca26d28bSVarad Gautam static inline struct vc4_exec_info * 786ca26d28bSVarad Gautam vc4_first_render_job(struct vc4_dev *vc4) 787ca26d28bSVarad Gautam { 78857b9f569SMasahiro Yamada return list_first_entry_or_null(&vc4->render_job_list, 789ca26d28bSVarad Gautam struct vc4_exec_info, head); 790d5b1a78aSEric Anholt } 791d5b1a78aSEric Anholt 7929326e6f2SEric Anholt static inline struct vc4_exec_info * 7939326e6f2SEric Anholt vc4_last_render_job(struct vc4_dev *vc4) 7949326e6f2SEric Anholt { 7959326e6f2SEric Anholt if (list_empty(&vc4->render_job_list)) 7969326e6f2SEric Anholt return NULL; 7979326e6f2SEric Anholt return list_last_entry(&vc4->render_job_list, 7989326e6f2SEric Anholt struct vc4_exec_info, head); 7999326e6f2SEric Anholt } 8009326e6f2SEric Anholt 801c8b75bcaSEric Anholt /** 802463873d5SEric Anholt * struct vc4_texture_sample_info - saves the offsets into the UBO for texture 803463873d5SEric Anholt * setup parameters. 804463873d5SEric Anholt * 805463873d5SEric Anholt * This will be used at draw time to relocate the reference to the texture 806463873d5SEric Anholt * contents in p0, and validate that the offset combined with 807463873d5SEric Anholt * width/height/stride/etc. from p1 and p2/p3 doesn't sample outside the BO. 808463873d5SEric Anholt * Note that the hardware treats unprovided config parameters as 0, so not all 809463873d5SEric Anholt * of them need to be set up for every texure sample, and we'll store ~0 as 810463873d5SEric Anholt * the offset to mark the unused ones. 811463873d5SEric Anholt * 812463873d5SEric Anholt * See the VC4 3D architecture guide page 41 ("Texture and Memory Lookup Unit 813463873d5SEric Anholt * Setup") for definitions of the texture parameters. 814463873d5SEric Anholt */ 815463873d5SEric Anholt struct vc4_texture_sample_info { 816463873d5SEric Anholt bool is_direct; 817463873d5SEric Anholt uint32_t p_offset[4]; 818463873d5SEric Anholt }; 819463873d5SEric Anholt 820463873d5SEric Anholt /** 821463873d5SEric Anholt * struct vc4_validated_shader_info - information about validated shaders that 822463873d5SEric Anholt * needs to be used from command list validation. 823463873d5SEric Anholt * 824463873d5SEric Anholt * For a given shader, each time a shader state record references it, we need 825463873d5SEric Anholt * to verify that the shader doesn't read more uniforms than the shader state 826463873d5SEric Anholt * record's uniform BO pointer can provide, and we need to apply relocations 827463873d5SEric Anholt * and validate the shader state record's uniforms that define the texture 828463873d5SEric Anholt * samples. 829463873d5SEric Anholt */ 830463873d5SEric Anholt struct vc4_validated_shader_info { 831463873d5SEric Anholt uint32_t uniforms_size; 832463873d5SEric Anholt uint32_t uniforms_src_size; 833463873d5SEric Anholt uint32_t num_texture_samples; 834463873d5SEric Anholt struct vc4_texture_sample_info *texture_samples; 8356d45c81dSEric Anholt 8366d45c81dSEric Anholt uint32_t num_uniform_addr_offsets; 8376d45c81dSEric Anholt uint32_t *uniform_addr_offsets; 838c778cc5dSJonas Pfeil 839c778cc5dSJonas Pfeil bool is_threaded; 840463873d5SEric Anholt }; 841463873d5SEric Anholt 842463873d5SEric Anholt /** 8437f2a09ecSJames Hughes * __wait_for - magic wait macro 844c8b75bcaSEric Anholt * 8457f2a09ecSJames Hughes * Macro to help avoid open coding check/wait/timeout patterns. Note that it's 8467f2a09ecSJames Hughes * important that we check the condition again after having timed out, since the 8477f2a09ecSJames Hughes * timeout could be due to preemption or similar and we've never had a chance to 8487f2a09ecSJames Hughes * check the condition before the timeout. 849c8b75bcaSEric Anholt */ 8507f2a09ecSJames Hughes #define __wait_for(OP, COND, US, Wmin, Wmax) ({ \ 8517f2a09ecSJames Hughes const ktime_t end__ = ktime_add_ns(ktime_get_raw(), 1000ll * (US)); \ 8527f2a09ecSJames Hughes long wait__ = (Wmin); /* recommended min for usleep is 10 us */ \ 8537f2a09ecSJames Hughes int ret__; \ 8547f2a09ecSJames Hughes might_sleep(); \ 8557f2a09ecSJames Hughes for (;;) { \ 8567f2a09ecSJames Hughes const bool expired__ = ktime_after(ktime_get_raw(), end__); \ 8577f2a09ecSJames Hughes OP; \ 8587f2a09ecSJames Hughes /* Guarantee COND check prior to timeout */ \ 8597f2a09ecSJames Hughes barrier(); \ 8607f2a09ecSJames Hughes if (COND) { \ 8617f2a09ecSJames Hughes ret__ = 0; \ 8627f2a09ecSJames Hughes break; \ 8637f2a09ecSJames Hughes } \ 8647f2a09ecSJames Hughes if (expired__) { \ 865c8b75bcaSEric Anholt ret__ = -ETIMEDOUT; \ 866c8b75bcaSEric Anholt break; \ 867c8b75bcaSEric Anholt } \ 8687f2a09ecSJames Hughes usleep_range(wait__, wait__ * 2); \ 8697f2a09ecSJames Hughes if (wait__ < (Wmax)) \ 8707f2a09ecSJames Hughes wait__ <<= 1; \ 871c8b75bcaSEric Anholt } \ 872c8b75bcaSEric Anholt ret__; \ 873c8b75bcaSEric Anholt }) 874c8b75bcaSEric Anholt 8757f2a09ecSJames Hughes #define _wait_for(COND, US, Wmin, Wmax) __wait_for(, (COND), (US), (Wmin), \ 8767f2a09ecSJames Hughes (Wmax)) 8777f2a09ecSJames Hughes #define wait_for(COND, MS) _wait_for((COND), (MS) * 1000, 10, 1000) 878c8b75bcaSEric Anholt 879c8b75bcaSEric Anholt /* vc4_bo.c */ 880c826a6e1SEric Anholt struct drm_gem_object *vc4_create_object(struct drm_device *dev, size_t size); 881c826a6e1SEric Anholt struct vc4_bo *vc4_bo_create(struct drm_device *dev, size_t size, 882f3099462SEric Anholt bool from_cache, enum vc4_kernel_bo_type type); 883dd2dfd44SMaxime Ripard int vc4_bo_dumb_create(struct drm_file *file_priv, 884c8b75bcaSEric Anholt struct drm_device *dev, 885c8b75bcaSEric Anholt struct drm_mode_create_dumb *args); 886d5bc60f6SEric Anholt int vc4_create_bo_ioctl(struct drm_device *dev, void *data, 887d5bc60f6SEric Anholt struct drm_file *file_priv); 888463873d5SEric Anholt int vc4_create_shader_bo_ioctl(struct drm_device *dev, void *data, 889463873d5SEric Anholt struct drm_file *file_priv); 890d5bc60f6SEric Anholt int vc4_mmap_bo_ioctl(struct drm_device *dev, void *data, 891d5bc60f6SEric Anholt struct drm_file *file_priv); 89283753117SEric Anholt int vc4_set_tiling_ioctl(struct drm_device *dev, void *data, 89383753117SEric Anholt struct drm_file *file_priv); 89483753117SEric Anholt int vc4_get_tiling_ioctl(struct drm_device *dev, void *data, 89583753117SEric Anholt struct drm_file *file_priv); 89621461365SEric Anholt int vc4_get_hang_state_ioctl(struct drm_device *dev, void *data, 89721461365SEric Anholt struct drm_file *file_priv); 898f3099462SEric Anholt int vc4_label_bo_ioctl(struct drm_device *dev, void *data, 899f3099462SEric Anholt struct drm_file *file_priv); 900f3099462SEric Anholt int vc4_bo_cache_init(struct drm_device *dev); 901b9f19259SBoris Brezillon int vc4_bo_inc_usecnt(struct vc4_bo *bo); 902b9f19259SBoris Brezillon void vc4_bo_dec_usecnt(struct vc4_bo *bo); 903b9f19259SBoris Brezillon void vc4_bo_add_to_purgeable_pool(struct vc4_bo *bo); 904b9f19259SBoris Brezillon void vc4_bo_remove_from_purgeable_pool(struct vc4_bo *bo); 905445b287eSMaxime Ripard int vc4_bo_debugfs_init(struct drm_minor *minor); 906c8b75bcaSEric Anholt 907c8b75bcaSEric Anholt /* vc4_crtc.c */ 908c8b75bcaSEric Anholt extern struct platform_driver vc4_crtc_driver; 909875a4d53SMaxime Ripard int vc4_crtc_disable_at_boot(struct drm_crtc *crtc); 910ee33ac27SMaxime Ripard int __vc4_crtc_init(struct drm_device *drm, struct platform_device *pdev, 911ee33ac27SMaxime Ripard struct vc4_crtc *vc4_crtc, const struct vc4_crtc_data *data, 912ee33ac27SMaxime Ripard struct drm_plane *primary_plane, 913ee33ac27SMaxime Ripard const struct drm_crtc_funcs *crtc_funcs, 914ee33ac27SMaxime Ripard const struct drm_crtc_helper_funcs *crtc_helper_funcs, 915ee33ac27SMaxime Ripard bool feeds_txp); 9163f98076fSMaxime Ripard int vc4_crtc_init(struct drm_device *drm, struct platform_device *pdev, 9173f98076fSMaxime Ripard struct vc4_crtc *vc4_crtc, const struct vc4_crtc_data *data, 9185fefc601SMaxime Ripard const struct drm_crtc_funcs *crtc_funcs, 9193f98076fSMaxime Ripard const struct drm_crtc_helper_funcs *crtc_helper_funcs, 9203f98076fSMaxime Ripard bool feeds_txp); 921bdd96472SMaxime Ripard int vc4_page_flip(struct drm_crtc *crtc, 922bdd96472SMaxime Ripard struct drm_framebuffer *fb, 923bdd96472SMaxime Ripard struct drm_pending_vblank_event *event, 924bdd96472SMaxime Ripard uint32_t flags, 925bdd96472SMaxime Ripard struct drm_modeset_acquire_ctx *ctx); 926f759f5b5SMaxime Ripard int vc4_crtc_atomic_check(struct drm_crtc *crtc, 927f759f5b5SMaxime Ripard struct drm_atomic_state *state); 928bdd96472SMaxime Ripard struct drm_crtc_state *vc4_crtc_duplicate_state(struct drm_crtc *crtc); 929bdd96472SMaxime Ripard void vc4_crtc_destroy_state(struct drm_crtc *crtc, 930bdd96472SMaxime Ripard struct drm_crtc_state *state); 931bdd96472SMaxime Ripard void vc4_crtc_reset(struct drm_crtc *crtc); 932008095e0SBoris Brezillon void vc4_crtc_handle_vblank(struct vc4_crtc *crtc); 93368e4a69aSMaxime Ripard void vc4_crtc_send_vblank(struct drm_crtc *crtc); 934445b287eSMaxime Ripard int vc4_crtc_late_register(struct drm_crtc *crtc); 935666e7358SBoris Brezillon void vc4_crtc_get_margins(struct drm_crtc_state *state, 936e590c2b0SDan Carpenter unsigned int *left, unsigned int *right, 937666e7358SBoris Brezillon unsigned int *top, unsigned int *bottom); 938c8b75bcaSEric Anholt 939c8b75bcaSEric Anholt /* vc4_debugfs.c */ 9407ce84471SWambui Karuga void vc4_debugfs_init(struct drm_minor *minor); 941c9be804cSEric Anholt #ifdef CONFIG_DEBUG_FS 942f2ede40eSMaíra Canal void vc4_debugfs_add_regset32(struct drm_device *drm, 943c9be804cSEric Anholt const char *filename, 944c9be804cSEric Anholt struct debugfs_regset32 *regset); 945c9be804cSEric Anholt #else 946c9be804cSEric Anholt 947f2ede40eSMaíra Canal static inline void vc4_debugfs_add_regset32(struct drm_device *drm, 948c9be804cSEric Anholt const char *filename, 949c9be804cSEric Anholt struct debugfs_regset32 *regset) 950f2ede40eSMaíra Canal {} 951c9be804cSEric Anholt #endif 952c8b75bcaSEric Anholt 953c8b75bcaSEric Anholt /* vc4_drv.c */ 954c8b75bcaSEric Anholt void __iomem *vc4_ioremap_regs(struct platform_device *dev, int index); 9553d763742SMaxime Ripard int vc4_dumb_fixup_args(struct drm_mode_create_dumb *args); 956c8b75bcaSEric Anholt 95708302c35SEric Anholt /* vc4_dpi.c */ 95808302c35SEric Anholt extern struct platform_driver vc4_dpi_driver; 95908302c35SEric Anholt 9604078f575SEric Anholt /* vc4_dsi.c */ 9614078f575SEric Anholt extern struct platform_driver vc4_dsi_driver; 9624078f575SEric Anholt 963cdec4d36SEric Anholt /* vc4_fence.c */ 964cdec4d36SEric Anholt extern const struct dma_fence_ops vc4_fence_ops; 965cdec4d36SEric Anholt 966d5b1a78aSEric Anholt /* vc4_gem.c */ 967171a072bSMaxime Ripard int vc4_gem_init(struct drm_device *dev); 968d5b1a78aSEric Anholt int vc4_submit_cl_ioctl(struct drm_device *dev, void *data, 969d5b1a78aSEric Anholt struct drm_file *file_priv); 970d5b1a78aSEric Anholt int vc4_wait_seqno_ioctl(struct drm_device *dev, void *data, 971d5b1a78aSEric Anholt struct drm_file *file_priv); 972d5b1a78aSEric Anholt int vc4_wait_bo_ioctl(struct drm_device *dev, void *data, 973d5b1a78aSEric Anholt struct drm_file *file_priv); 974ca26d28bSVarad Gautam void vc4_submit_next_bin_job(struct drm_device *dev); 975ca26d28bSVarad Gautam void vc4_submit_next_render_job(struct drm_device *dev); 976ca26d28bSVarad Gautam void vc4_move_job_to_render(struct drm_device *dev, struct vc4_exec_info *exec); 977d5b1a78aSEric Anholt int vc4_wait_for_seqno(struct drm_device *dev, uint64_t seqno, 978d5b1a78aSEric Anholt uint64_t timeout_ns, bool interruptible); 979d5b1a78aSEric Anholt void vc4_job_handle_completed(struct vc4_dev *vc4); 980b501baccSEric Anholt int vc4_queue_seqno_cb(struct drm_device *dev, 981b501baccSEric Anholt struct vc4_seqno_cb *cb, uint64_t seqno, 982b501baccSEric Anholt void (*func)(struct vc4_seqno_cb *cb)); 983b9f19259SBoris Brezillon int vc4_gem_madvise_ioctl(struct drm_device *dev, void *data, 984b9f19259SBoris Brezillon struct drm_file *file_priv); 985d5b1a78aSEric Anholt 986c8b75bcaSEric Anholt /* vc4_hdmi.c */ 987c8b75bcaSEric Anholt extern struct platform_driver vc4_hdmi_driver; 988c8b75bcaSEric Anholt 9899a8d5e4aSBoris Brezillon /* vc4_vec.c */ 990e4b81f8cSBoris Brezillon extern struct platform_driver vc4_vec_driver; 991e4b81f8cSBoris Brezillon 992008095e0SBoris Brezillon /* vc4_txp.c */ 993008095e0SBoris Brezillon extern struct platform_driver vc4_txp_driver; 994008095e0SBoris Brezillon 995d5b1a78aSEric Anholt /* vc4_irq.c */ 9965226711eSThomas Zimmermann void vc4_irq_enable(struct drm_device *dev); 9975226711eSThomas Zimmermann void vc4_irq_disable(struct drm_device *dev); 9985226711eSThomas Zimmermann int vc4_irq_install(struct drm_device *dev, int irq); 999d5b1a78aSEric Anholt void vc4_irq_uninstall(struct drm_device *dev); 1000d5b1a78aSEric Anholt void vc4_irq_reset(struct drm_device *dev); 1001d5b1a78aSEric Anholt 1002c8b75bcaSEric Anholt /* vc4_hvs.c */ 1003c8b75bcaSEric Anholt extern struct platform_driver vc4_hvs_driver; 1004640dbcc9SMaxime Ripard struct vc4_hvs *__vc4_hvs_alloc(struct vc4_dev *vc4, struct platform_device *pdev); 10053454f01aSMaxime Ripard void vc4_hvs_stop_channel(struct vc4_hvs *hvs, unsigned int output); 10063454f01aSMaxime Ripard int vc4_hvs_get_fifo_from_output(struct vc4_hvs *hvs, unsigned int output); 10073454f01aSMaxime Ripard u8 vc4_hvs_get_fifo_frame_count(struct vc4_hvs *hvs, unsigned int fifo); 1008ee6965c8SMaxime Ripard int vc4_hvs_atomic_check(struct drm_crtc *crtc, struct drm_atomic_state *state); 1009eeb6ab46SMaxime Ripard void vc4_hvs_atomic_begin(struct drm_crtc *crtc, struct drm_atomic_state *state); 1010ee6965c8SMaxime Ripard void vc4_hvs_atomic_enable(struct drm_crtc *crtc, struct drm_atomic_state *state); 1011ee6965c8SMaxime Ripard void vc4_hvs_atomic_disable(struct drm_crtc *crtc, struct drm_atomic_state *state); 1012ee6965c8SMaxime Ripard void vc4_hvs_atomic_flush(struct drm_crtc *crtc, struct drm_atomic_state *state); 10133454f01aSMaxime Ripard void vc4_hvs_dump_state(struct vc4_hvs *hvs); 10143454f01aSMaxime Ripard void vc4_hvs_unmask_underrun(struct vc4_hvs *hvs, int channel); 10153454f01aSMaxime Ripard void vc4_hvs_mask_underrun(struct vc4_hvs *hvs, int channel); 1016445b287eSMaxime Ripard int vc4_hvs_debugfs_init(struct drm_minor *minor); 1017c8b75bcaSEric Anholt 1018c8b75bcaSEric Anholt /* vc4_kms.c */ 1019c8b75bcaSEric Anholt int vc4_kms_load(struct drm_device *dev); 1020c8b75bcaSEric Anholt 1021c8b75bcaSEric Anholt /* vc4_plane.c */ 1022c8b75bcaSEric Anholt struct drm_plane *vc4_plane_init(struct drm_device *dev, 102377c5fb12SMaxime Ripard enum drm_plane_type type, 102477c5fb12SMaxime Ripard uint32_t possible_crtcs); 10250c2a50f1SMaxime Ripard int vc4_plane_create_additional_planes(struct drm_device *dev); 1026c8b75bcaSEric Anholt u32 vc4_plane_write_dlist(struct drm_plane *plane, u32 __iomem *dlist); 10272f196b7cSDaniel Vetter u32 vc4_plane_dlist_size(const struct drm_plane_state *state); 1028b501baccSEric Anholt void vc4_plane_async_set_fb(struct drm_plane *plane, 1029b501baccSEric Anholt struct drm_framebuffer *fb); 1030463873d5SEric Anholt 1031d3f5168aSEric Anholt /* vc4_v3d.c */ 1032d3f5168aSEric Anholt extern struct platform_driver vc4_v3d_driver; 1033ffc26740SEric Anholt extern const struct of_device_id vc4_v3d_dt_match[]; 1034553c942fSEric Anholt int vc4_v3d_get_bin_slot(struct vc4_dev *vc4); 103535c8b4b2SPaul Kocialkowski int vc4_v3d_bin_bo_get(struct vc4_dev *vc4, bool *used); 103635c8b4b2SPaul Kocialkowski void vc4_v3d_bin_bo_put(struct vc4_dev *vc4); 1037cb74f6eeSEric Anholt int vc4_v3d_pm_get(struct vc4_dev *vc4); 1038cb74f6eeSEric Anholt void vc4_v3d_pm_put(struct vc4_dev *vc4); 1039445b287eSMaxime Ripard int vc4_v3d_debugfs_init(struct drm_minor *minor); 1040d5b1a78aSEric Anholt 1041d5b1a78aSEric Anholt /* vc4_validate.c */ 1042d5b1a78aSEric Anholt int 1043d5b1a78aSEric Anholt vc4_validate_bin_cl(struct drm_device *dev, 1044d5b1a78aSEric Anholt void *validated, 1045d5b1a78aSEric Anholt void *unvalidated, 1046d5b1a78aSEric Anholt struct vc4_exec_info *exec); 1047d5b1a78aSEric Anholt 1048d5b1a78aSEric Anholt int 1049d5b1a78aSEric Anholt vc4_validate_shader_recs(struct drm_device *dev, struct vc4_exec_info *exec); 1050d5b1a78aSEric Anholt 10514a83c26aSDanilo Krummrich struct drm_gem_dma_object *vc4_use_bo(struct vc4_exec_info *exec, 1052d5b1a78aSEric Anholt uint32_t hindex); 1053d5b1a78aSEric Anholt 1054d5b1a78aSEric Anholt int vc4_get_rcl(struct drm_device *dev, struct vc4_exec_info *exec); 1055d5b1a78aSEric Anholt 1056d5b1a78aSEric Anholt bool vc4_check_tex_size(struct vc4_exec_info *exec, 10574a83c26aSDanilo Krummrich struct drm_gem_dma_object *fbo, 1058d5b1a78aSEric Anholt uint32_t offset, uint8_t tiling_format, 1059d5b1a78aSEric Anholt uint32_t width, uint32_t height, uint8_t cpp); 1060d3f5168aSEric Anholt 1061463873d5SEric Anholt /* vc4_validate_shader.c */ 1062463873d5SEric Anholt struct vc4_validated_shader_info * 10634a83c26aSDanilo Krummrich vc4_validate_shader(struct drm_gem_dma_object *shader_obj); 106465101d8cSBoris Brezillon 106565101d8cSBoris Brezillon /* vc4_perfmon.c */ 106665101d8cSBoris Brezillon void vc4_perfmon_get(struct vc4_perfmon *perfmon); 106765101d8cSBoris Brezillon void vc4_perfmon_put(struct vc4_perfmon *perfmon); 106865101d8cSBoris Brezillon void vc4_perfmon_start(struct vc4_dev *vc4, struct vc4_perfmon *perfmon); 106965101d8cSBoris Brezillon void vc4_perfmon_stop(struct vc4_dev *vc4, struct vc4_perfmon *perfmon, 107065101d8cSBoris Brezillon bool capture); 107165101d8cSBoris Brezillon struct vc4_perfmon *vc4_perfmon_find(struct vc4_file *vc4file, int id); 107265101d8cSBoris Brezillon void vc4_perfmon_open_file(struct vc4_file *vc4file); 107365101d8cSBoris Brezillon void vc4_perfmon_close_file(struct vc4_file *vc4file); 107465101d8cSBoris Brezillon int vc4_perfmon_create_ioctl(struct drm_device *dev, void *data, 107565101d8cSBoris Brezillon struct drm_file *file_priv); 107665101d8cSBoris Brezillon int vc4_perfmon_destroy_ioctl(struct drm_device *dev, void *data, 107765101d8cSBoris Brezillon struct drm_file *file_priv); 107865101d8cSBoris Brezillon int vc4_perfmon_get_values_ioctl(struct drm_device *dev, void *data, 107965101d8cSBoris Brezillon struct drm_file *file_priv); 10806a88752cSMaxime Ripard 10816a88752cSMaxime Ripard #endif /* _VC4_DRV_H_ */ 1082