Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-only */
0002 /*
0003  * Copyright (C) 2015 Broadcom
0004  */
0005 #ifndef _VC4_DRV_H_
0006 #define _VC4_DRV_H_
0007 
0008 #include <linux/delay.h>
0009 #include <linux/of.h>
0010 #include <linux/refcount.h>
0011 #include <linux/uaccess.h>
0012 
0013 #include <drm/drm_atomic.h>
0014 #include <drm/drm_debugfs.h>
0015 #include <drm/drm_device.h>
0016 #include <drm/drm_encoder.h>
0017 #include <drm/drm_gem_cma_helper.h>
0018 #include <drm/drm_managed.h>
0019 #include <drm/drm_mm.h>
0020 #include <drm/drm_modeset_lock.h>
0021 
0022 #include "uapi/drm/vc4_drm.h"
0023 
0024 struct drm_device;
0025 struct drm_gem_object;
0026 
0027 /* Don't forget to update vc4_bo.c: bo_type_names[] when adding to
0028  * this.
0029  */
0030 enum vc4_kernel_bo_type {
0031     /* Any kernel allocation (gem_create_object hook) before it
0032      * gets another type set.
0033      */
0034     VC4_BO_TYPE_KERNEL,
0035     VC4_BO_TYPE_V3D,
0036     VC4_BO_TYPE_V3D_SHADER,
0037     VC4_BO_TYPE_DUMB,
0038     VC4_BO_TYPE_BIN,
0039     VC4_BO_TYPE_RCL,
0040     VC4_BO_TYPE_BCL,
0041     VC4_BO_TYPE_KERNEL_CACHE,
0042     VC4_BO_TYPE_COUNT
0043 };
0044 
0045 /* Performance monitor object. The perform lifetime is controlled by userspace
0046  * using perfmon related ioctls. A perfmon can be attached to a submit_cl
0047  * request, and when this is the case, HW perf counters will be activated just
0048  * before the submit_cl is submitted to the GPU and disabled when the job is
0049  * done. This way, only events related to a specific job will be counted.
0050  */
0051 struct vc4_perfmon {
0052     struct vc4_dev *dev;
0053 
0054     /* Tracks the number of users of the perfmon, when this counter reaches
0055      * zero the perfmon is destroyed.
0056      */
0057     refcount_t refcnt;
0058 
0059     /* Number of counters activated in this perfmon instance
0060      * (should be less than DRM_VC4_MAX_PERF_COUNTERS).
0061      */
0062     u8 ncounters;
0063 
0064     /* Events counted by the HW perf counters. */
0065     u8 events[DRM_VC4_MAX_PERF_COUNTERS];
0066 
0067     /* Storage for counter values. Counters are incremented by the HW
0068      * perf counter values every time the perfmon is attached to a GPU job.
0069      * This way, perfmon users don't have to retrieve the results after
0070      * each job if they want to track events covering several submissions.
0071      * Note that counter values can't be reset, but you can fake a reset by
0072      * destroying the perfmon and creating a new one.
0073      */
0074     u64 counters[];
0075 };
0076 
0077 struct vc4_dev {
0078     struct drm_device base;
0079 
0080     bool is_vc5;
0081 
0082     unsigned int irq;
0083 
0084     struct vc4_hvs *hvs;
0085     struct vc4_v3d *v3d;
0086     struct vc4_dpi *dpi;
0087     struct vc4_vec *vec;
0088     struct vc4_txp *txp;
0089 
0090     struct vc4_hang_state *hang_state;
0091 
0092     /* The kernel-space BO cache.  Tracks buffers that have been
0093      * unreferenced by all other users (refcounts of 0!) but not
0094      * yet freed, so we can do cheap allocations.
0095      */
0096     struct vc4_bo_cache {
0097         /* Array of list heads for entries in the BO cache,
0098          * based on number of pages, so we can do O(1) lookups
0099          * in the cache when allocating.
0100          */
0101         struct list_head *size_list;
0102         uint32_t size_list_size;
0103 
0104         /* List of all BOs in the cache, ordered by age, so we
0105          * can do O(1) lookups when trying to free old
0106          * buffers.
0107          */
0108         struct list_head time_list;
0109         struct work_struct time_work;
0110         struct timer_list time_timer;
0111     } bo_cache;
0112 
0113     u32 num_labels;
0114     struct vc4_label {
0115         const char *name;
0116         u32 num_allocated;
0117         u32 size_allocated;
0118     } *bo_labels;
0119 
0120     /* Protects bo_cache and bo_labels. */
0121     struct mutex bo_lock;
0122 
0123     /* Purgeable BO pool. All BOs in this pool can have their memory
0124      * reclaimed if the driver is unable to allocate new BOs. We also
0125      * keep stats related to the purge mechanism here.
0126      */
0127     struct {
0128         struct list_head list;
0129         unsigned int num;
0130         size_t size;
0131         unsigned int purged_num;
0132         size_t purged_size;
0133         struct mutex lock;
0134     } purgeable;
0135 
0136     uint64_t dma_fence_context;
0137 
0138     /* Sequence number for the last job queued in bin_job_list.
0139      * Starts at 0 (no jobs emitted).
0140      */
0141     uint64_t emit_seqno;
0142 
0143     /* Sequence number for the last completed job on the GPU.
0144      * Starts at 0 (no jobs completed).
0145      */
0146     uint64_t finished_seqno;
0147 
0148     /* List of all struct vc4_exec_info for jobs to be executed in
0149      * the binner.  The first job in the list is the one currently
0150      * programmed into ct0ca for execution.
0151      */
0152     struct list_head bin_job_list;
0153 
0154     /* List of all struct vc4_exec_info for jobs that have
0155      * completed binning and are ready for rendering.  The first
0156      * job in the list is the one currently programmed into ct1ca
0157      * for execution.
0158      */
0159     struct list_head render_job_list;
0160 
0161     /* List of the finished vc4_exec_infos waiting to be freed by
0162      * job_done_work.
0163      */
0164     struct list_head job_done_list;
0165     /* Spinlock used to synchronize the job_list and seqno
0166      * accesses between the IRQ handler and GEM ioctls.
0167      */
0168     spinlock_t job_lock;
0169     wait_queue_head_t job_wait_queue;
0170     struct work_struct job_done_work;
0171 
0172     /* Used to track the active perfmon if any. Access to this field is
0173      * protected by job_lock.
0174      */
0175     struct vc4_perfmon *active_perfmon;
0176 
0177     /* List of struct vc4_seqno_cb for callbacks to be made from a
0178      * workqueue when the given seqno is passed.
0179      */
0180     struct list_head seqno_cb_list;
0181 
0182     /* The memory used for storing binner tile alloc, tile state,
0183      * and overflow memory allocations.  This is freed when V3D
0184      * powers down.
0185      */
0186     struct vc4_bo *bin_bo;
0187 
0188     /* Size of blocks allocated within bin_bo. */
0189     uint32_t bin_alloc_size;
0190 
0191     /* Bitmask of the bin_alloc_size chunks in bin_bo that are
0192      * used.
0193      */
0194     uint32_t bin_alloc_used;
0195 
0196     /* Bitmask of the current bin_alloc used for overflow memory. */
0197     uint32_t bin_alloc_overflow;
0198 
0199     /* Incremented when an underrun error happened after an atomic commit.
0200      * This is particularly useful to detect when a specific modeset is too
0201      * demanding in term of memory or HVS bandwidth which is hard to guess
0202      * at atomic check time.
0203      */
0204     atomic_t underrun;
0205 
0206     struct work_struct overflow_mem_work;
0207 
0208     int power_refcount;
0209 
0210     /* Set to true when the load tracker is active. */
0211     bool load_tracker_enabled;
0212 
0213     /* Mutex controlling the power refcount. */
0214     struct mutex power_lock;
0215 
0216     struct {
0217         struct timer_list timer;
0218         struct work_struct reset_work;
0219     } hangcheck;
0220 
0221     struct drm_modeset_lock ctm_state_lock;
0222     struct drm_private_obj ctm_manager;
0223     struct drm_private_obj hvs_channels;
0224     struct drm_private_obj load_tracker;
0225 
0226     /* List of vc4_debugfs_info_entry for adding to debugfs once
0227      * the minor is available (after drm_dev_register()).
0228      */
0229     struct list_head debugfs_list;
0230 
0231     /* Mutex for binner bo allocation. */
0232     struct mutex bin_bo_lock;
0233     /* Reference count for our binner bo. */
0234     struct kref bin_bo_kref;
0235 };
0236 
0237 static inline struct vc4_dev *
0238 to_vc4_dev(struct drm_device *dev)
0239 {
0240     return container_of(dev, struct vc4_dev, base);
0241 }
0242 
0243 struct vc4_bo {
0244     struct drm_gem_cma_object base;
0245 
0246     /* seqno of the last job to render using this BO. */
0247     uint64_t seqno;
0248 
0249     /* seqno of the last job to use the RCL to write to this BO.
0250      *
0251      * Note that this doesn't include binner overflow memory
0252      * writes.
0253      */
0254     uint64_t write_seqno;
0255 
0256     bool t_format;
0257 
0258     /* List entry for the BO's position in either
0259      * vc4_exec_info->unref_list or vc4_dev->bo_cache.time_list
0260      */
0261     struct list_head unref_head;
0262 
0263     /* Time in jiffies when the BO was put in vc4->bo_cache. */
0264     unsigned long free_time;
0265 
0266     /* List entry for the BO's position in vc4_dev->bo_cache.size_list */
0267     struct list_head size_head;
0268 
0269     /* Struct for shader validation state, if created by
0270      * DRM_IOCTL_VC4_CREATE_SHADER_BO.
0271      */
0272     struct vc4_validated_shader_info *validated_shader;
0273 
0274     /* One of enum vc4_kernel_bo_type, or VC4_BO_TYPE_COUNT + i
0275      * for user-allocated labels.
0276      */
0277     int label;
0278 
0279     /* Count the number of active users. This is needed to determine
0280      * whether we can move the BO to the purgeable list or not (when the BO
0281      * is used by the GPU or the display engine we can't purge it).
0282      */
0283     refcount_t usecnt;
0284 
0285     /* Store purgeable/purged state here */
0286     u32 madv;
0287     struct mutex madv_lock;
0288 };
0289 
0290 static inline struct vc4_bo *
0291 to_vc4_bo(struct drm_gem_object *bo)
0292 {
0293     return container_of(to_drm_gem_cma_obj(bo), struct vc4_bo, base);
0294 }
0295 
0296 struct vc4_fence {
0297     struct dma_fence base;
0298     struct drm_device *dev;
0299     /* vc4 seqno for signaled() test */
0300     uint64_t seqno;
0301 };
0302 
0303 static inline struct vc4_fence *
0304 to_vc4_fence(struct dma_fence *fence)
0305 {
0306     return container_of(fence, struct vc4_fence, base);
0307 }
0308 
0309 struct vc4_seqno_cb {
0310     struct work_struct work;
0311     uint64_t seqno;
0312     void (*func)(struct vc4_seqno_cb *cb);
0313 };
0314 
0315 struct vc4_v3d {
0316     struct vc4_dev *vc4;
0317     struct platform_device *pdev;
0318     void __iomem *regs;
0319     struct clk *clk;
0320     struct debugfs_regset32 regset;
0321 };
0322 
0323 struct vc4_hvs {
0324     struct vc4_dev *vc4;
0325     struct platform_device *pdev;
0326     void __iomem *regs;
0327     u32 __iomem *dlist;
0328 
0329     struct clk *core_clk;
0330 
0331     /* Memory manager for CRTCs to allocate space in the display
0332      * list.  Units are dwords.
0333      */
0334     struct drm_mm dlist_mm;
0335     /* Memory manager for the LBM memory used by HVS scaling. */
0336     struct drm_mm lbm_mm;
0337     spinlock_t mm_lock;
0338 
0339     struct drm_mm_node mitchell_netravali_filter;
0340 
0341     struct debugfs_regset32 regset;
0342 };
0343 
0344 struct vc4_plane {
0345     struct drm_plane base;
0346 };
0347 
0348 static inline struct vc4_plane *
0349 to_vc4_plane(struct drm_plane *plane)
0350 {
0351     return container_of(plane, struct vc4_plane, base);
0352 }
0353 
0354 enum vc4_scaling_mode {
0355     VC4_SCALING_NONE,
0356     VC4_SCALING_TPZ,
0357     VC4_SCALING_PPF,
0358 };
0359 
0360 struct vc4_plane_state {
0361     struct drm_plane_state base;
0362     /* System memory copy of the display list for this element, computed
0363      * at atomic_check time.
0364      */
0365     u32 *dlist;
0366     u32 dlist_size; /* Number of dwords allocated for the display list */
0367     u32 dlist_count; /* Number of used dwords in the display list. */
0368 
0369     /* Offset in the dlist to various words, for pageflip or
0370      * cursor updates.
0371      */
0372     u32 pos0_offset;
0373     u32 pos2_offset;
0374     u32 ptr0_offset;
0375     u32 lbm_offset;
0376 
0377     /* Offset where the plane's dlist was last stored in the
0378      * hardware at vc4_crtc_atomic_flush() time.
0379      */
0380     u32 __iomem *hw_dlist;
0381 
0382     /* Clipped coordinates of the plane on the display. */
0383     int crtc_x, crtc_y, crtc_w, crtc_h;
0384     /* Clipped area being scanned from in the FB. */
0385     u32 src_x, src_y;
0386 
0387     u32 src_w[2], src_h[2];
0388 
0389     /* Scaling selection for the RGB/Y plane and the Cb/Cr planes. */
0390     enum vc4_scaling_mode x_scaling[2], y_scaling[2];
0391     bool is_unity;
0392     bool is_yuv;
0393 
0394     /* Offset to start scanning out from the start of the plane's
0395      * BO.
0396      */
0397     u32 offsets[3];
0398 
0399     /* Our allocation in LBM for temporary storage during scaling. */
0400     struct drm_mm_node lbm;
0401 
0402     /* Set when the plane has per-pixel alpha content or does not cover
0403      * the entire screen. This is a hint to the CRTC that it might need
0404      * to enable background color fill.
0405      */
0406     bool needs_bg_fill;
0407 
0408     /* Mark the dlist as initialized. Useful to avoid initializing it twice
0409      * when async update is not possible.
0410      */
0411     bool dlist_initialized;
0412 
0413     /* Load of this plane on the HVS block. The load is expressed in HVS
0414      * cycles/sec.
0415      */
0416     u64 hvs_load;
0417 
0418     /* Memory bandwidth needed for this plane. This is expressed in
0419      * bytes/sec.
0420      */
0421     u64 membus_load;
0422 };
0423 
0424 static inline struct vc4_plane_state *
0425 to_vc4_plane_state(struct drm_plane_state *state)
0426 {
0427     return container_of(state, struct vc4_plane_state, base);
0428 }
0429 
0430 enum vc4_encoder_type {
0431     VC4_ENCODER_TYPE_NONE,
0432     VC4_ENCODER_TYPE_HDMI0,
0433     VC4_ENCODER_TYPE_HDMI1,
0434     VC4_ENCODER_TYPE_VEC,
0435     VC4_ENCODER_TYPE_DSI0,
0436     VC4_ENCODER_TYPE_DSI1,
0437     VC4_ENCODER_TYPE_SMI,
0438     VC4_ENCODER_TYPE_DPI,
0439 };
0440 
0441 struct vc4_encoder {
0442     struct drm_encoder base;
0443     enum vc4_encoder_type type;
0444     u32 clock_select;
0445 
0446     void (*pre_crtc_configure)(struct drm_encoder *encoder, struct drm_atomic_state *state);
0447     void (*pre_crtc_enable)(struct drm_encoder *encoder, struct drm_atomic_state *state);
0448     void (*post_crtc_enable)(struct drm_encoder *encoder, struct drm_atomic_state *state);
0449 
0450     void (*post_crtc_disable)(struct drm_encoder *encoder, struct drm_atomic_state *state);
0451     void (*post_crtc_powerdown)(struct drm_encoder *encoder, struct drm_atomic_state *state);
0452 };
0453 
0454 static inline struct vc4_encoder *
0455 to_vc4_encoder(struct drm_encoder *encoder)
0456 {
0457     return container_of(encoder, struct vc4_encoder, base);
0458 }
0459 
0460 struct vc4_crtc_data {
0461     /* Bitmask of channels (FIFOs) of the HVS that the output can source from */
0462     unsigned int hvs_available_channels;
0463 
0464     /* Which output of the HVS this pixelvalve sources from. */
0465     int hvs_output;
0466 };
0467 
0468 struct vc4_pv_data {
0469     struct vc4_crtc_data    base;
0470 
0471     /* Depth of the PixelValve FIFO in bytes */
0472     unsigned int fifo_depth;
0473 
0474     /* Number of pixels output per clock period */
0475     u8 pixels_per_clock;
0476 
0477     enum vc4_encoder_type encoder_types[4];
0478     const char *debugfs_name;
0479 
0480 };
0481 
0482 struct vc4_crtc {
0483     struct drm_crtc base;
0484     struct platform_device *pdev;
0485     const struct vc4_crtc_data *data;
0486     void __iomem *regs;
0487 
0488     /* Timestamp at start of vblank irq - unaffected by lock delays. */
0489     ktime_t t_vblank;
0490 
0491     u8 lut_r[256];
0492     u8 lut_g[256];
0493     u8 lut_b[256];
0494 
0495     struct drm_pending_vblank_event *event;
0496 
0497     struct debugfs_regset32 regset;
0498 
0499     /**
0500      * @feeds_txp: True if the CRTC feeds our writeback controller.
0501      */
0502     bool feeds_txp;
0503 
0504     /**
0505      * @irq_lock: Spinlock protecting the resources shared between
0506      * the atomic code and our vblank handler.
0507      */
0508     spinlock_t irq_lock;
0509 
0510     /**
0511      * @current_dlist: Start offset of the display list currently
0512      * set in the HVS for that CRTC. Protected by @irq_lock, and
0513      * copied in vc4_hvs_update_dlist() for the CRTC interrupt
0514      * handler to have access to that value.
0515      */
0516     unsigned int current_dlist;
0517 
0518     /**
0519      * @current_hvs_channel: HVS channel currently assigned to the
0520      * CRTC. Protected by @irq_lock, and copied in
0521      * vc4_hvs_atomic_begin() for the CRTC interrupt handler to have
0522      * access to that value.
0523      */
0524     unsigned int current_hvs_channel;
0525 };
0526 
0527 static inline struct vc4_crtc *
0528 to_vc4_crtc(struct drm_crtc *crtc)
0529 {
0530     return container_of(crtc, struct vc4_crtc, base);
0531 }
0532 
0533 static inline const struct vc4_crtc_data *
0534 vc4_crtc_to_vc4_crtc_data(const struct vc4_crtc *crtc)
0535 {
0536     return crtc->data;
0537 }
0538 
0539 static inline const struct vc4_pv_data *
0540 vc4_crtc_to_vc4_pv_data(const struct vc4_crtc *crtc)
0541 {
0542     const struct vc4_crtc_data *data = vc4_crtc_to_vc4_crtc_data(crtc);
0543 
0544     return container_of(data, struct vc4_pv_data, base);
0545 }
0546 
0547 struct drm_encoder *vc4_get_crtc_encoder(struct drm_crtc *crtc,
0548                      struct drm_crtc_state *state);
0549 
0550 struct vc4_crtc_state {
0551     struct drm_crtc_state base;
0552     /* Dlist area for this CRTC configuration. */
0553     struct drm_mm_node mm;
0554     bool txp_armed;
0555     unsigned int assigned_channel;
0556 
0557     struct {
0558         unsigned int left;
0559         unsigned int right;
0560         unsigned int top;
0561         unsigned int bottom;
0562     } margins;
0563 
0564     unsigned long hvs_load;
0565 
0566     /* Transitional state below, only valid during atomic commits */
0567     bool update_muxing;
0568 };
0569 
0570 #define VC4_HVS_CHANNEL_DISABLED ((unsigned int)-1)
0571 
0572 static inline struct vc4_crtc_state *
0573 to_vc4_crtc_state(struct drm_crtc_state *crtc_state)
0574 {
0575     return container_of(crtc_state, struct vc4_crtc_state, base);
0576 }
0577 
0578 #define V3D_READ(offset) readl(vc4->v3d->regs + offset)
0579 #define V3D_WRITE(offset, val) writel(val, vc4->v3d->regs + offset)
0580 #define HVS_READ(offset) readl(hvs->regs + offset)
0581 #define HVS_WRITE(offset, val) writel(val, hvs->regs + offset)
0582 
0583 #define VC4_REG32(reg) { .name = #reg, .offset = reg }
0584 
0585 struct vc4_exec_info {
0586     struct vc4_dev *dev;
0587 
0588     /* Sequence number for this bin/render job. */
0589     uint64_t seqno;
0590 
0591     /* Latest write_seqno of any BO that binning depends on. */
0592     uint64_t bin_dep_seqno;
0593 
0594     struct dma_fence *fence;
0595 
0596     /* Last current addresses the hardware was processing when the
0597      * hangcheck timer checked on us.
0598      */
0599     uint32_t last_ct0ca, last_ct1ca;
0600 
0601     /* Kernel-space copy of the ioctl arguments */
0602     struct drm_vc4_submit_cl *args;
0603 
0604     /* This is the array of BOs that were looked up at the start of exec.
0605      * Command validation will use indices into this array.
0606      */
0607     struct drm_gem_cma_object **bo;
0608     uint32_t bo_count;
0609 
0610     /* List of BOs that are being written by the RCL.  Other than
0611      * the binner temporary storage, this is all the BOs written
0612      * by the job.
0613      */
0614     struct drm_gem_cma_object *rcl_write_bo[4];
0615     uint32_t rcl_write_bo_count;
0616 
0617     /* Pointers for our position in vc4->job_list */
0618     struct list_head head;
0619 
0620     /* List of other BOs used in the job that need to be released
0621      * once the job is complete.
0622      */
0623     struct list_head unref_list;
0624 
0625     /* Current unvalidated indices into @bo loaded by the non-hardware
0626      * VC4_PACKET_GEM_HANDLES.
0627      */
0628     uint32_t bo_index[2];
0629 
0630     /* This is the BO where we store the validated command lists, shader
0631      * records, and uniforms.
0632      */
0633     struct drm_gem_cma_object *exec_bo;
0634 
0635     /**
0636      * This tracks the per-shader-record state (packet 64) that
0637      * determines the length of the shader record and the offset
0638      * it's expected to be found at.  It gets read in from the
0639      * command lists.
0640      */
0641     struct vc4_shader_state {
0642         uint32_t addr;
0643         /* Maximum vertex index referenced by any primitive using this
0644          * shader state.
0645          */
0646         uint32_t max_index;
0647     } *shader_state;
0648 
0649     /** How many shader states the user declared they were using. */
0650     uint32_t shader_state_size;
0651     /** How many shader state records the validator has seen. */
0652     uint32_t shader_state_count;
0653 
0654     bool found_tile_binning_mode_config_packet;
0655     bool found_start_tile_binning_packet;
0656     bool found_increment_semaphore_packet;
0657     bool found_flush;
0658     uint8_t bin_tiles_x, bin_tiles_y;
0659     /* Physical address of the start of the tile alloc array
0660      * (where each tile's binned CL will start)
0661      */
0662     uint32_t tile_alloc_offset;
0663     /* Bitmask of which binner slots are freed when this job completes. */
0664     uint32_t bin_slots;
0665 
0666     /**
0667      * Computed addresses pointing into exec_bo where we start the
0668      * bin thread (ct0) and render thread (ct1).
0669      */
0670     uint32_t ct0ca, ct0ea;
0671     uint32_t ct1ca, ct1ea;
0672 
0673     /* Pointer to the unvalidated bin CL (if present). */
0674     void *bin_u;
0675 
0676     /* Pointers to the shader recs.  These paddr gets incremented as CL
0677      * packets are relocated in validate_gl_shader_state, and the vaddrs
0678      * (u and v) get incremented and size decremented as the shader recs
0679      * themselves are validated.
0680      */
0681     void *shader_rec_u;
0682     void *shader_rec_v;
0683     uint32_t shader_rec_p;
0684     uint32_t shader_rec_size;
0685 
0686     /* Pointers to the uniform data.  These pointers are incremented, and
0687      * size decremented, as each batch of uniforms is uploaded.
0688      */
0689     void *uniforms_u;
0690     void *uniforms_v;
0691     uint32_t uniforms_p;
0692     uint32_t uniforms_size;
0693 
0694     /* Pointer to a performance monitor object if the user requested it,
0695      * NULL otherwise.
0696      */
0697     struct vc4_perfmon *perfmon;
0698 
0699     /* Whether the exec has taken a reference to the binner BO, which should
0700      * happen with a VC4_PACKET_TILE_BINNING_MODE_CONFIG packet.
0701      */
0702     bool bin_bo_used;
0703 };
0704 
0705 /* Per-open file private data. Any driver-specific resource that has to be
0706  * released when the DRM file is closed should be placed here.
0707  */
0708 struct vc4_file {
0709     struct vc4_dev *dev;
0710 
0711     struct {
0712         struct idr idr;
0713         struct mutex lock;
0714     } perfmon;
0715 
0716     bool bin_bo_used;
0717 };
0718 
0719 static inline struct vc4_exec_info *
0720 vc4_first_bin_job(struct vc4_dev *vc4)
0721 {
0722     return list_first_entry_or_null(&vc4->bin_job_list,
0723                     struct vc4_exec_info, head);
0724 }
0725 
0726 static inline struct vc4_exec_info *
0727 vc4_first_render_job(struct vc4_dev *vc4)
0728 {
0729     return list_first_entry_or_null(&vc4->render_job_list,
0730                     struct vc4_exec_info, head);
0731 }
0732 
0733 static inline struct vc4_exec_info *
0734 vc4_last_render_job(struct vc4_dev *vc4)
0735 {
0736     if (list_empty(&vc4->render_job_list))
0737         return NULL;
0738     return list_last_entry(&vc4->render_job_list,
0739                    struct vc4_exec_info, head);
0740 }
0741 
0742 /**
0743  * struct vc4_texture_sample_info - saves the offsets into the UBO for texture
0744  * setup parameters.
0745  *
0746  * This will be used at draw time to relocate the reference to the texture
0747  * contents in p0, and validate that the offset combined with
0748  * width/height/stride/etc. from p1 and p2/p3 doesn't sample outside the BO.
0749  * Note that the hardware treats unprovided config parameters as 0, so not all
0750  * of them need to be set up for every texure sample, and we'll store ~0 as
0751  * the offset to mark the unused ones.
0752  *
0753  * See the VC4 3D architecture guide page 41 ("Texture and Memory Lookup Unit
0754  * Setup") for definitions of the texture parameters.
0755  */
0756 struct vc4_texture_sample_info {
0757     bool is_direct;
0758     uint32_t p_offset[4];
0759 };
0760 
0761 /**
0762  * struct vc4_validated_shader_info - information about validated shaders that
0763  * needs to be used from command list validation.
0764  *
0765  * For a given shader, each time a shader state record references it, we need
0766  * to verify that the shader doesn't read more uniforms than the shader state
0767  * record's uniform BO pointer can provide, and we need to apply relocations
0768  * and validate the shader state record's uniforms that define the texture
0769  * samples.
0770  */
0771 struct vc4_validated_shader_info {
0772     uint32_t uniforms_size;
0773     uint32_t uniforms_src_size;
0774     uint32_t num_texture_samples;
0775     struct vc4_texture_sample_info *texture_samples;
0776 
0777     uint32_t num_uniform_addr_offsets;
0778     uint32_t *uniform_addr_offsets;
0779 
0780     bool is_threaded;
0781 };
0782 
0783 /**
0784  * __wait_for - magic wait macro
0785  *
0786  * Macro to help avoid open coding check/wait/timeout patterns. Note that it's
0787  * important that we check the condition again after having timed out, since the
0788  * timeout could be due to preemption or similar and we've never had a chance to
0789  * check the condition before the timeout.
0790  */
0791 #define __wait_for(OP, COND, US, Wmin, Wmax) ({ \
0792     const ktime_t end__ = ktime_add_ns(ktime_get_raw(), 1000ll * (US)); \
0793     long wait__ = (Wmin); /* recommended min for usleep is 10 us */ \
0794     int ret__;                          \
0795     might_sleep();                          \
0796     for (;;) {                          \
0797         const bool expired__ = ktime_after(ktime_get_raw(), end__); \
0798         OP;                         \
0799         /* Guarantee COND check prior to timeout */     \
0800         barrier();                      \
0801         if (COND) {                     \
0802             ret__ = 0;                  \
0803             break;                      \
0804         }                           \
0805         if (expired__) {                    \
0806             ret__ = -ETIMEDOUT;             \
0807             break;                      \
0808         }                           \
0809         usleep_range(wait__, wait__ * 2);           \
0810         if (wait__ < (Wmax))                    \
0811             wait__ <<= 1;                   \
0812     }                               \
0813     ret__;                              \
0814 })
0815 
0816 #define _wait_for(COND, US, Wmin, Wmax) __wait_for(, (COND), (US), (Wmin), \
0817                            (Wmax))
0818 #define wait_for(COND, MS)      _wait_for((COND), (MS) * 1000, 10, 1000)
0819 
0820 /* vc4_bo.c */
0821 struct drm_gem_object *vc4_create_object(struct drm_device *dev, size_t size);
0822 struct vc4_bo *vc4_bo_create(struct drm_device *dev, size_t size,
0823                  bool from_cache, enum vc4_kernel_bo_type type);
0824 int vc4_bo_dumb_create(struct drm_file *file_priv,
0825                struct drm_device *dev,
0826                struct drm_mode_create_dumb *args);
0827 int vc4_create_bo_ioctl(struct drm_device *dev, void *data,
0828             struct drm_file *file_priv);
0829 int vc4_create_shader_bo_ioctl(struct drm_device *dev, void *data,
0830                    struct drm_file *file_priv);
0831 int vc4_mmap_bo_ioctl(struct drm_device *dev, void *data,
0832               struct drm_file *file_priv);
0833 int vc4_set_tiling_ioctl(struct drm_device *dev, void *data,
0834              struct drm_file *file_priv);
0835 int vc4_get_tiling_ioctl(struct drm_device *dev, void *data,
0836              struct drm_file *file_priv);
0837 int vc4_get_hang_state_ioctl(struct drm_device *dev, void *data,
0838                  struct drm_file *file_priv);
0839 int vc4_label_bo_ioctl(struct drm_device *dev, void *data,
0840                struct drm_file *file_priv);
0841 int vc4_bo_cache_init(struct drm_device *dev);
0842 int vc4_bo_inc_usecnt(struct vc4_bo *bo);
0843 void vc4_bo_dec_usecnt(struct vc4_bo *bo);
0844 void vc4_bo_add_to_purgeable_pool(struct vc4_bo *bo);
0845 void vc4_bo_remove_from_purgeable_pool(struct vc4_bo *bo);
0846 
0847 /* vc4_crtc.c */
0848 extern struct platform_driver vc4_crtc_driver;
0849 int vc4_crtc_disable_at_boot(struct drm_crtc *crtc);
0850 int vc4_crtc_init(struct drm_device *drm, struct vc4_crtc *vc4_crtc,
0851           const struct drm_crtc_funcs *crtc_funcs,
0852           const struct drm_crtc_helper_funcs *crtc_helper_funcs);
0853 void vc4_crtc_destroy(struct drm_crtc *crtc);
0854 int vc4_page_flip(struct drm_crtc *crtc,
0855           struct drm_framebuffer *fb,
0856           struct drm_pending_vblank_event *event,
0857           uint32_t flags,
0858           struct drm_modeset_acquire_ctx *ctx);
0859 struct drm_crtc_state *vc4_crtc_duplicate_state(struct drm_crtc *crtc);
0860 void vc4_crtc_destroy_state(struct drm_crtc *crtc,
0861                 struct drm_crtc_state *state);
0862 void vc4_crtc_reset(struct drm_crtc *crtc);
0863 void vc4_crtc_handle_vblank(struct vc4_crtc *crtc);
0864 void vc4_crtc_get_margins(struct drm_crtc_state *state,
0865               unsigned int *left, unsigned int *right,
0866               unsigned int *top, unsigned int *bottom);
0867 
0868 /* vc4_debugfs.c */
0869 void vc4_debugfs_init(struct drm_minor *minor);
0870 #ifdef CONFIG_DEBUG_FS
0871 void vc4_debugfs_add_file(struct drm_device *drm,
0872               const char *filename,
0873               int (*show)(struct seq_file*, void*),
0874               void *data);
0875 void vc4_debugfs_add_regset32(struct drm_device *drm,
0876                   const char *filename,
0877                   struct debugfs_regset32 *regset);
0878 #else
0879 static inline void vc4_debugfs_add_file(struct drm_device *drm,
0880                     const char *filename,
0881                     int (*show)(struct seq_file*, void*),
0882                     void *data)
0883 {
0884 }
0885 
0886 static inline void vc4_debugfs_add_regset32(struct drm_device *drm,
0887                         const char *filename,
0888                         struct debugfs_regset32 *regset)
0889 {
0890 }
0891 #endif
0892 
0893 /* vc4_drv.c */
0894 void __iomem *vc4_ioremap_regs(struct platform_device *dev, int index);
0895 int vc4_dumb_fixup_args(struct drm_mode_create_dumb *args);
0896 
0897 /* vc4_dpi.c */
0898 extern struct platform_driver vc4_dpi_driver;
0899 
0900 /* vc4_dsi.c */
0901 extern struct platform_driver vc4_dsi_driver;
0902 
0903 /* vc4_fence.c */
0904 extern const struct dma_fence_ops vc4_fence_ops;
0905 
0906 /* vc4_gem.c */
0907 int vc4_gem_init(struct drm_device *dev);
0908 int vc4_submit_cl_ioctl(struct drm_device *dev, void *data,
0909             struct drm_file *file_priv);
0910 int vc4_wait_seqno_ioctl(struct drm_device *dev, void *data,
0911              struct drm_file *file_priv);
0912 int vc4_wait_bo_ioctl(struct drm_device *dev, void *data,
0913               struct drm_file *file_priv);
0914 void vc4_submit_next_bin_job(struct drm_device *dev);
0915 void vc4_submit_next_render_job(struct drm_device *dev);
0916 void vc4_move_job_to_render(struct drm_device *dev, struct vc4_exec_info *exec);
0917 int vc4_wait_for_seqno(struct drm_device *dev, uint64_t seqno,
0918                uint64_t timeout_ns, bool interruptible);
0919 void vc4_job_handle_completed(struct vc4_dev *vc4);
0920 int vc4_queue_seqno_cb(struct drm_device *dev,
0921                struct vc4_seqno_cb *cb, uint64_t seqno,
0922                void (*func)(struct vc4_seqno_cb *cb));
0923 int vc4_gem_madvise_ioctl(struct drm_device *dev, void *data,
0924               struct drm_file *file_priv);
0925 
0926 /* vc4_hdmi.c */
0927 extern struct platform_driver vc4_hdmi_driver;
0928 
0929 /* vc4_vec.c */
0930 extern struct platform_driver vc4_vec_driver;
0931 
0932 /* vc4_txp.c */
0933 extern struct platform_driver vc4_txp_driver;
0934 
0935 /* vc4_irq.c */
0936 void vc4_irq_enable(struct drm_device *dev);
0937 void vc4_irq_disable(struct drm_device *dev);
0938 int vc4_irq_install(struct drm_device *dev, int irq);
0939 void vc4_irq_uninstall(struct drm_device *dev);
0940 void vc4_irq_reset(struct drm_device *dev);
0941 
0942 /* vc4_hvs.c */
0943 extern struct platform_driver vc4_hvs_driver;
0944 void vc4_hvs_stop_channel(struct vc4_hvs *hvs, unsigned int output);
0945 int vc4_hvs_get_fifo_from_output(struct vc4_hvs *hvs, unsigned int output);
0946 u8 vc4_hvs_get_fifo_frame_count(struct vc4_hvs *hvs, unsigned int fifo);
0947 int vc4_hvs_atomic_check(struct drm_crtc *crtc, struct drm_atomic_state *state);
0948 void vc4_hvs_atomic_begin(struct drm_crtc *crtc, struct drm_atomic_state *state);
0949 void vc4_hvs_atomic_enable(struct drm_crtc *crtc, struct drm_atomic_state *state);
0950 void vc4_hvs_atomic_disable(struct drm_crtc *crtc, struct drm_atomic_state *state);
0951 void vc4_hvs_atomic_flush(struct drm_crtc *crtc, struct drm_atomic_state *state);
0952 void vc4_hvs_dump_state(struct vc4_hvs *hvs);
0953 void vc4_hvs_unmask_underrun(struct vc4_hvs *hvs, int channel);
0954 void vc4_hvs_mask_underrun(struct vc4_hvs *hvs, int channel);
0955 
0956 /* vc4_kms.c */
0957 int vc4_kms_load(struct drm_device *dev);
0958 
0959 /* vc4_plane.c */
0960 struct drm_plane *vc4_plane_init(struct drm_device *dev,
0961                  enum drm_plane_type type);
0962 int vc4_plane_create_additional_planes(struct drm_device *dev);
0963 u32 vc4_plane_write_dlist(struct drm_plane *plane, u32 __iomem *dlist);
0964 u32 vc4_plane_dlist_size(const struct drm_plane_state *state);
0965 void vc4_plane_async_set_fb(struct drm_plane *plane,
0966                 struct drm_framebuffer *fb);
0967 
0968 /* vc4_v3d.c */
0969 extern struct platform_driver vc4_v3d_driver;
0970 extern const struct of_device_id vc4_v3d_dt_match[];
0971 int vc4_v3d_get_bin_slot(struct vc4_dev *vc4);
0972 int vc4_v3d_bin_bo_get(struct vc4_dev *vc4, bool *used);
0973 void vc4_v3d_bin_bo_put(struct vc4_dev *vc4);
0974 int vc4_v3d_pm_get(struct vc4_dev *vc4);
0975 void vc4_v3d_pm_put(struct vc4_dev *vc4);
0976 
0977 /* vc4_validate.c */
0978 int
0979 vc4_validate_bin_cl(struct drm_device *dev,
0980             void *validated,
0981             void *unvalidated,
0982             struct vc4_exec_info *exec);
0983 
0984 int
0985 vc4_validate_shader_recs(struct drm_device *dev, struct vc4_exec_info *exec);
0986 
0987 struct drm_gem_cma_object *vc4_use_bo(struct vc4_exec_info *exec,
0988                       uint32_t hindex);
0989 
0990 int vc4_get_rcl(struct drm_device *dev, struct vc4_exec_info *exec);
0991 
0992 bool vc4_check_tex_size(struct vc4_exec_info *exec,
0993             struct drm_gem_cma_object *fbo,
0994             uint32_t offset, uint8_t tiling_format,
0995             uint32_t width, uint32_t height, uint8_t cpp);
0996 
0997 /* vc4_validate_shader.c */
0998 struct vc4_validated_shader_info *
0999 vc4_validate_shader(struct drm_gem_cma_object *shader_obj);
1000 
1001 /* vc4_perfmon.c */
1002 void vc4_perfmon_get(struct vc4_perfmon *perfmon);
1003 void vc4_perfmon_put(struct vc4_perfmon *perfmon);
1004 void vc4_perfmon_start(struct vc4_dev *vc4, struct vc4_perfmon *perfmon);
1005 void vc4_perfmon_stop(struct vc4_dev *vc4, struct vc4_perfmon *perfmon,
1006               bool capture);
1007 struct vc4_perfmon *vc4_perfmon_find(struct vc4_file *vc4file, int id);
1008 void vc4_perfmon_open_file(struct vc4_file *vc4file);
1009 void vc4_perfmon_close_file(struct vc4_file *vc4file);
1010 int vc4_perfmon_create_ioctl(struct drm_device *dev, void *data,
1011                  struct drm_file *file_priv);
1012 int vc4_perfmon_destroy_ioctl(struct drm_device *dev, void *data,
1013                   struct drm_file *file_priv);
1014 int vc4_perfmon_get_values_ioctl(struct drm_device *dev, void *data,
1015                  struct drm_file *file_priv);
1016 
1017 #endif /* _VC4_DRV_H_ */