vc4_drv.h 29 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (C) 2015 Broadcom
  4. */
  5. #ifndef _VC4_DRV_H_
  6. #define _VC4_DRV_H_
  7. #include <linux/delay.h>
  8. #include <linux/of.h>
  9. #include <linux/refcount.h>
  10. #include <linux/uaccess.h>
  11. #include <drm/drm_atomic.h>
  12. #include <drm/drm_debugfs.h>
  13. #include <drm/drm_device.h>
  14. #include <drm/drm_encoder.h>
  15. #include <drm/drm_gem_dma_helper.h>
  16. #include <drm/drm_managed.h>
  17. #include <drm/drm_mm.h>
  18. #include <drm/drm_modeset_lock.h>
  19. #include "uapi/drm/vc4_drm.h"
  20. struct drm_device;
  21. struct drm_gem_object;
  22. /* Don't forget to update vc4_bo.c: bo_type_names[] when adding to
  23. * this.
  24. */
  25. enum vc4_kernel_bo_type {
  26. /* Any kernel allocation (gem_create_object hook) before it
  27. * gets another type set.
  28. */
  29. VC4_BO_TYPE_KERNEL,
  30. VC4_BO_TYPE_V3D,
  31. VC4_BO_TYPE_V3D_SHADER,
  32. VC4_BO_TYPE_DUMB,
  33. VC4_BO_TYPE_BIN,
  34. VC4_BO_TYPE_RCL,
  35. VC4_BO_TYPE_BCL,
  36. VC4_BO_TYPE_KERNEL_CACHE,
  37. VC4_BO_TYPE_COUNT
  38. };
  39. /* Performance monitor object. The perform lifetime is controlled by userspace
  40. * using perfmon related ioctls. A perfmon can be attached to a submit_cl
  41. * request, and when this is the case, HW perf counters will be activated just
  42. * before the submit_cl is submitted to the GPU and disabled when the job is
  43. * done. This way, only events related to a specific job will be counted.
  44. */
  45. struct vc4_perfmon {
  46. struct vc4_dev *dev;
  47. /* Tracks the number of users of the perfmon, when this counter reaches
  48. * zero the perfmon is destroyed.
  49. */
  50. refcount_t refcnt;
  51. /* Number of counters activated in this perfmon instance
  52. * (should be less than DRM_VC4_MAX_PERF_COUNTERS).
  53. */
  54. u8 ncounters;
  55. /* Events counted by the HW perf counters. */
  56. u8 events[DRM_VC4_MAX_PERF_COUNTERS];
  57. /* Storage for counter values. Counters are incremented by the HW
  58. * perf counter values every time the perfmon is attached to a GPU job.
  59. * This way, perfmon users don't have to retrieve the results after
  60. * each job if they want to track events covering several submissions.
  61. * Note that counter values can't be reset, but you can fake a reset by
  62. * destroying the perfmon and creating a new one.
  63. */
  64. u64 counters[];
  65. };
  66. struct vc4_dev {
  67. struct drm_device base;
  68. struct device *dev;
  69. bool is_vc5;
  70. unsigned int irq;
  71. struct vc4_hvs *hvs;
  72. struct vc4_v3d *v3d;
  73. struct vc4_hang_state *hang_state;
  74. /* The kernel-space BO cache. Tracks buffers that have been
  75. * unreferenced by all other users (refcounts of 0!) but not
  76. * yet freed, so we can do cheap allocations.
  77. */
  78. struct vc4_bo_cache {
  79. /* Array of list heads for entries in the BO cache,
  80. * based on number of pages, so we can do O(1) lookups
  81. * in the cache when allocating.
  82. */
  83. struct list_head *size_list;
  84. uint32_t size_list_size;
  85. /* List of all BOs in the cache, ordered by age, so we
  86. * can do O(1) lookups when trying to free old
  87. * buffers.
  88. */
  89. struct list_head time_list;
  90. struct work_struct time_work;
  91. struct timer_list time_timer;
  92. } bo_cache;
  93. u32 num_labels;
  94. struct vc4_label {
  95. const char *name;
  96. u32 num_allocated;
  97. u32 size_allocated;
  98. } *bo_labels;
  99. /* Protects bo_cache and bo_labels. */
  100. struct mutex bo_lock;
  101. /* Purgeable BO pool. All BOs in this pool can have their memory
  102. * reclaimed if the driver is unable to allocate new BOs. We also
  103. * keep stats related to the purge mechanism here.
  104. */
  105. struct {
  106. struct list_head list;
  107. unsigned int num;
  108. size_t size;
  109. unsigned int purged_num;
  110. size_t purged_size;
  111. struct mutex lock;
  112. } purgeable;
  113. uint64_t dma_fence_context;
  114. /* Sequence number for the last job queued in bin_job_list.
  115. * Starts at 0 (no jobs emitted).
  116. */
  117. uint64_t emit_seqno;
  118. /* Sequence number for the last completed job on the GPU.
  119. * Starts at 0 (no jobs completed).
  120. */
  121. uint64_t finished_seqno;
  122. /* List of all struct vc4_exec_info for jobs to be executed in
  123. * the binner. The first job in the list is the one currently
  124. * programmed into ct0ca for execution.
  125. */
  126. struct list_head bin_job_list;
  127. /* List of all struct vc4_exec_info for jobs that have
  128. * completed binning and are ready for rendering. The first
  129. * job in the list is the one currently programmed into ct1ca
  130. * for execution.
  131. */
  132. struct list_head render_job_list;
  133. /* List of the finished vc4_exec_infos waiting to be freed by
  134. * job_done_work.
  135. */
  136. struct list_head job_done_list;
  137. /* Spinlock used to synchronize the job_list and seqno
  138. * accesses between the IRQ handler and GEM ioctls.
  139. */
  140. spinlock_t job_lock;
  141. wait_queue_head_t job_wait_queue;
  142. struct work_struct job_done_work;
  143. /* Used to track the active perfmon if any. Access to this field is
  144. * protected by job_lock.
  145. */
  146. struct vc4_perfmon *active_perfmon;
  147. /* List of struct vc4_seqno_cb for callbacks to be made from a
  148. * workqueue when the given seqno is passed.
  149. */
  150. struct list_head seqno_cb_list;
  151. /* The memory used for storing binner tile alloc, tile state,
  152. * and overflow memory allocations. This is freed when V3D
  153. * powers down.
  154. */
  155. struct vc4_bo *bin_bo;
  156. /* Size of blocks allocated within bin_bo. */
  157. uint32_t bin_alloc_size;
  158. /* Bitmask of the bin_alloc_size chunks in bin_bo that are
  159. * used.
  160. */
  161. uint32_t bin_alloc_used;
  162. /* Bitmask of the current bin_alloc used for overflow memory. */
  163. uint32_t bin_alloc_overflow;
  164. /* Incremented when an underrun error happened after an atomic commit.
  165. * This is particularly useful to detect when a specific modeset is too
  166. * demanding in term of memory or HVS bandwidth which is hard to guess
  167. * at atomic check time.
  168. */
  169. atomic_t underrun;
  170. struct work_struct overflow_mem_work;
  171. int power_refcount;
  172. /* Set to true when the load tracker is active. */
  173. bool load_tracker_enabled;
  174. /* Mutex controlling the power refcount. */
  175. struct mutex power_lock;
  176. struct {
  177. struct timer_list timer;
  178. struct work_struct reset_work;
  179. } hangcheck;
  180. struct drm_modeset_lock ctm_state_lock;
  181. struct drm_private_obj ctm_manager;
  182. struct drm_private_obj hvs_channels;
  183. struct drm_private_obj load_tracker;
  184. /* List of vc4_debugfs_info_entry for adding to debugfs once
  185. * the minor is available (after drm_dev_register()).
  186. */
  187. struct list_head debugfs_list;
  188. /* Mutex for binner bo allocation. */
  189. struct mutex bin_bo_lock;
  190. /* Reference count for our binner bo. */
  191. struct kref bin_bo_kref;
  192. };
  193. static inline struct vc4_dev *
  194. to_vc4_dev(struct drm_device *dev)
  195. {
  196. return container_of(dev, struct vc4_dev, base);
  197. }
  198. struct vc4_bo {
  199. struct drm_gem_dma_object base;
  200. /* seqno of the last job to render using this BO. */
  201. uint64_t seqno;
  202. /* seqno of the last job to use the RCL to write to this BO.
  203. *
  204. * Note that this doesn't include binner overflow memory
  205. * writes.
  206. */
  207. uint64_t write_seqno;
  208. bool t_format;
  209. /* List entry for the BO's position in either
  210. * vc4_exec_info->unref_list or vc4_dev->bo_cache.time_list
  211. */
  212. struct list_head unref_head;
  213. /* Time in jiffies when the BO was put in vc4->bo_cache. */
  214. unsigned long free_time;
  215. /* List entry for the BO's position in vc4_dev->bo_cache.size_list */
  216. struct list_head size_head;
  217. /* Struct for shader validation state, if created by
  218. * DRM_IOCTL_VC4_CREATE_SHADER_BO.
  219. */
  220. struct vc4_validated_shader_info *validated_shader;
  221. /* One of enum vc4_kernel_bo_type, or VC4_BO_TYPE_COUNT + i
  222. * for user-allocated labels.
  223. */
  224. int label;
  225. /* Count the number of active users. This is needed to determine
  226. * whether we can move the BO to the purgeable list or not (when the BO
  227. * is used by the GPU or the display engine we can't purge it).
  228. */
  229. refcount_t usecnt;
  230. /* Store purgeable/purged state here */
  231. u32 madv;
  232. struct mutex madv_lock;
  233. };
  234. static inline struct vc4_bo *
  235. to_vc4_bo(struct drm_gem_object *bo)
  236. {
  237. return container_of(to_drm_gem_dma_obj(bo), struct vc4_bo, base);
  238. }
  239. struct vc4_fence {
  240. struct dma_fence base;
  241. struct drm_device *dev;
  242. /* vc4 seqno for signaled() test */
  243. uint64_t seqno;
  244. };
  245. static inline struct vc4_fence *
  246. to_vc4_fence(struct dma_fence *fence)
  247. {
  248. return container_of(fence, struct vc4_fence, base);
  249. }
  250. struct vc4_seqno_cb {
  251. struct work_struct work;
  252. uint64_t seqno;
  253. void (*func)(struct vc4_seqno_cb *cb);
  254. };
  255. struct vc4_v3d {
  256. struct vc4_dev *vc4;
  257. struct platform_device *pdev;
  258. void __iomem *regs;
  259. struct clk *clk;
  260. struct debugfs_regset32 regset;
  261. };
  262. struct vc4_hvs {
  263. struct vc4_dev *vc4;
  264. struct platform_device *pdev;
  265. void __iomem *regs;
  266. u32 __iomem *dlist;
  267. struct clk *core_clk;
  268. /* Memory manager for CRTCs to allocate space in the display
  269. * list. Units are dwords.
  270. */
  271. struct drm_mm dlist_mm;
  272. /* Memory manager for the LBM memory used by HVS scaling. */
  273. struct drm_mm lbm_mm;
  274. spinlock_t mm_lock;
  275. struct drm_mm_node mitchell_netravali_filter;
  276. struct debugfs_regset32 regset;
  277. };
  278. struct vc4_plane {
  279. struct drm_plane base;
  280. };
  281. static inline struct vc4_plane *
  282. to_vc4_plane(struct drm_plane *plane)
  283. {
  284. return container_of(plane, struct vc4_plane, base);
  285. }
  286. enum vc4_scaling_mode {
  287. VC4_SCALING_NONE,
  288. VC4_SCALING_TPZ,
  289. VC4_SCALING_PPF,
  290. };
  291. struct vc4_plane_state {
  292. struct drm_plane_state base;
  293. /* System memory copy of the display list for this element, computed
  294. * at atomic_check time.
  295. */
  296. u32 *dlist;
  297. u32 dlist_size; /* Number of dwords allocated for the display list */
  298. u32 dlist_count; /* Number of used dwords in the display list. */
  299. /* Offset in the dlist to various words, for pageflip or
  300. * cursor updates.
  301. */
  302. u32 pos0_offset;
  303. u32 pos2_offset;
  304. u32 ptr0_offset;
  305. u32 lbm_offset;
  306. /* Offset where the plane's dlist was last stored in the
  307. * hardware at vc4_crtc_atomic_flush() time.
  308. */
  309. u32 __iomem *hw_dlist;
  310. /* Clipped coordinates of the plane on the display. */
  311. int crtc_x, crtc_y, crtc_w, crtc_h;
  312. /* Clipped area being scanned from in the FB. */
  313. u32 src_x, src_y;
  314. u32 src_w[2], src_h[2];
  315. /* Scaling selection for the RGB/Y plane and the Cb/Cr planes. */
  316. enum vc4_scaling_mode x_scaling[2], y_scaling[2];
  317. bool is_unity;
  318. bool is_yuv;
  319. /* Offset to start scanning out from the start of the plane's
  320. * BO.
  321. */
  322. u32 offsets[3];
  323. /* Our allocation in LBM for temporary storage during scaling. */
  324. struct drm_mm_node lbm;
  325. /* Set when the plane has per-pixel alpha content or does not cover
  326. * the entire screen. This is a hint to the CRTC that it might need
  327. * to enable background color fill.
  328. */
  329. bool needs_bg_fill;
  330. /* Mark the dlist as initialized. Useful to avoid initializing it twice
  331. * when async update is not possible.
  332. */
  333. bool dlist_initialized;
  334. /* Load of this plane on the HVS block. The load is expressed in HVS
  335. * cycles/sec.
  336. */
  337. u64 hvs_load;
  338. /* Memory bandwidth needed for this plane. This is expressed in
  339. * bytes/sec.
  340. */
  341. u64 membus_load;
  342. };
  343. static inline struct vc4_plane_state *
  344. to_vc4_plane_state(struct drm_plane_state *state)
  345. {
  346. return container_of(state, struct vc4_plane_state, base);
  347. }
  348. enum vc4_encoder_type {
  349. VC4_ENCODER_TYPE_NONE,
  350. VC4_ENCODER_TYPE_HDMI0,
  351. VC4_ENCODER_TYPE_HDMI1,
  352. VC4_ENCODER_TYPE_VEC,
  353. VC4_ENCODER_TYPE_DSI0,
  354. VC4_ENCODER_TYPE_DSI1,
  355. VC4_ENCODER_TYPE_SMI,
  356. VC4_ENCODER_TYPE_DPI,
  357. };
  358. struct vc4_encoder {
  359. struct drm_encoder base;
  360. enum vc4_encoder_type type;
  361. u32 clock_select;
  362. void (*pre_crtc_configure)(struct drm_encoder *encoder, struct drm_atomic_state *state);
  363. void (*pre_crtc_enable)(struct drm_encoder *encoder, struct drm_atomic_state *state);
  364. void (*post_crtc_enable)(struct drm_encoder *encoder, struct drm_atomic_state *state);
  365. void (*post_crtc_disable)(struct drm_encoder *encoder, struct drm_atomic_state *state);
  366. void (*post_crtc_powerdown)(struct drm_encoder *encoder, struct drm_atomic_state *state);
  367. };
  368. static inline struct vc4_encoder *
  369. to_vc4_encoder(struct drm_encoder *encoder)
  370. {
  371. return container_of(encoder, struct vc4_encoder, base);
  372. }
  373. struct vc4_crtc_data {
  374. const char *debugfs_name;
  375. /* Bitmask of channels (FIFOs) of the HVS that the output can source from */
  376. unsigned int hvs_available_channels;
  377. /* Which output of the HVS this pixelvalve sources from. */
  378. int hvs_output;
  379. };
  380. struct vc4_pv_data {
  381. struct vc4_crtc_data base;
  382. /* Depth of the PixelValve FIFO in bytes */
  383. unsigned int fifo_depth;
  384. /* Number of pixels output per clock period */
  385. u8 pixels_per_clock;
  386. enum vc4_encoder_type encoder_types[4];
  387. };
  388. struct vc4_crtc {
  389. struct drm_crtc base;
  390. struct platform_device *pdev;
  391. const struct vc4_crtc_data *data;
  392. void __iomem *regs;
  393. /* Timestamp at start of vblank irq - unaffected by lock delays. */
  394. ktime_t t_vblank;
  395. u8 lut_r[256];
  396. u8 lut_g[256];
  397. u8 lut_b[256];
  398. struct drm_pending_vblank_event *event;
  399. struct debugfs_regset32 regset;
  400. /**
  401. * @feeds_txp: True if the CRTC feeds our writeback controller.
  402. */
  403. bool feeds_txp;
  404. /**
  405. * @irq_lock: Spinlock protecting the resources shared between
  406. * the atomic code and our vblank handler.
  407. */
  408. spinlock_t irq_lock;
  409. /**
  410. * @current_dlist: Start offset of the display list currently
  411. * set in the HVS for that CRTC. Protected by @irq_lock, and
  412. * copied in vc4_hvs_update_dlist() for the CRTC interrupt
  413. * handler to have access to that value.
  414. */
  415. unsigned int current_dlist;
  416. /**
  417. * @current_hvs_channel: HVS channel currently assigned to the
  418. * CRTC. Protected by @irq_lock, and copied in
  419. * vc4_hvs_atomic_begin() for the CRTC interrupt handler to have
  420. * access to that value.
  421. */
  422. unsigned int current_hvs_channel;
  423. };
  424. static inline struct vc4_crtc *
  425. to_vc4_crtc(struct drm_crtc *crtc)
  426. {
  427. return container_of(crtc, struct vc4_crtc, base);
  428. }
  429. static inline const struct vc4_crtc_data *
  430. vc4_crtc_to_vc4_crtc_data(const struct vc4_crtc *crtc)
  431. {
  432. return crtc->data;
  433. }
  434. static inline const struct vc4_pv_data *
  435. vc4_crtc_to_vc4_pv_data(const struct vc4_crtc *crtc)
  436. {
  437. const struct vc4_crtc_data *data = vc4_crtc_to_vc4_crtc_data(crtc);
  438. return container_of(data, struct vc4_pv_data, base);
  439. }
  440. struct drm_encoder *vc4_get_crtc_encoder(struct drm_crtc *crtc,
  441. struct drm_crtc_state *state);
  442. struct vc4_crtc_state {
  443. struct drm_crtc_state base;
  444. /* Dlist area for this CRTC configuration. */
  445. struct drm_mm_node mm;
  446. bool txp_armed;
  447. unsigned int assigned_channel;
  448. struct {
  449. unsigned int left;
  450. unsigned int right;
  451. unsigned int top;
  452. unsigned int bottom;
  453. } margins;
  454. unsigned long hvs_load;
  455. /* Transitional state below, only valid during atomic commits */
  456. bool update_muxing;
  457. };
  458. #define VC4_HVS_CHANNEL_DISABLED ((unsigned int)-1)
  459. static inline struct vc4_crtc_state *
  460. to_vc4_crtc_state(struct drm_crtc_state *crtc_state)
  461. {
  462. return container_of(crtc_state, struct vc4_crtc_state, base);
  463. }
  464. #define V3D_READ(offset) readl(vc4->v3d->regs + offset)
  465. #define V3D_WRITE(offset, val) writel(val, vc4->v3d->regs + offset)
  466. #define HVS_READ(offset) readl(hvs->regs + offset)
  467. #define HVS_WRITE(offset, val) writel(val, hvs->regs + offset)
  468. #define VC4_REG32(reg) { .name = #reg, .offset = reg }
  469. struct vc4_exec_info {
  470. struct vc4_dev *dev;
  471. /* Sequence number for this bin/render job. */
  472. uint64_t seqno;
  473. /* Latest write_seqno of any BO that binning depends on. */
  474. uint64_t bin_dep_seqno;
  475. struct dma_fence *fence;
  476. /* Last current addresses the hardware was processing when the
  477. * hangcheck timer checked on us.
  478. */
  479. uint32_t last_ct0ca, last_ct1ca;
  480. /* Kernel-space copy of the ioctl arguments */
  481. struct drm_vc4_submit_cl *args;
  482. /* This is the array of BOs that were looked up at the start of exec.
  483. * Command validation will use indices into this array.
  484. */
  485. struct drm_gem_dma_object **bo;
  486. uint32_t bo_count;
  487. /* List of BOs that are being written by the RCL. Other than
  488. * the binner temporary storage, this is all the BOs written
  489. * by the job.
  490. */
  491. struct drm_gem_dma_object *rcl_write_bo[4];
  492. uint32_t rcl_write_bo_count;
  493. /* Pointers for our position in vc4->job_list */
  494. struct list_head head;
  495. /* List of other BOs used in the job that need to be released
  496. * once the job is complete.
  497. */
  498. struct list_head unref_list;
  499. /* Current unvalidated indices into @bo loaded by the non-hardware
  500. * VC4_PACKET_GEM_HANDLES.
  501. */
  502. uint32_t bo_index[2];
  503. /* This is the BO where we store the validated command lists, shader
  504. * records, and uniforms.
  505. */
  506. struct drm_gem_dma_object *exec_bo;
  507. /**
  508. * This tracks the per-shader-record state (packet 64) that
  509. * determines the length of the shader record and the offset
  510. * it's expected to be found at. It gets read in from the
  511. * command lists.
  512. */
  513. struct vc4_shader_state {
  514. uint32_t addr;
  515. /* Maximum vertex index referenced by any primitive using this
  516. * shader state.
  517. */
  518. uint32_t max_index;
  519. } *shader_state;
  520. /** How many shader states the user declared they were using. */
  521. uint32_t shader_state_size;
  522. /** How many shader state records the validator has seen. */
  523. uint32_t shader_state_count;
  524. bool found_tile_binning_mode_config_packet;
  525. bool found_start_tile_binning_packet;
  526. bool found_increment_semaphore_packet;
  527. bool found_flush;
  528. uint8_t bin_tiles_x, bin_tiles_y;
  529. /* Physical address of the start of the tile alloc array
  530. * (where each tile's binned CL will start)
  531. */
  532. uint32_t tile_alloc_offset;
  533. /* Bitmask of which binner slots are freed when this job completes. */
  534. uint32_t bin_slots;
  535. /**
  536. * Computed addresses pointing into exec_bo where we start the
  537. * bin thread (ct0) and render thread (ct1).
  538. */
  539. uint32_t ct0ca, ct0ea;
  540. uint32_t ct1ca, ct1ea;
  541. /* Pointer to the unvalidated bin CL (if present). */
  542. void *bin_u;
  543. /* Pointers to the shader recs. These paddr gets incremented as CL
  544. * packets are relocated in validate_gl_shader_state, and the vaddrs
  545. * (u and v) get incremented and size decremented as the shader recs
  546. * themselves are validated.
  547. */
  548. void *shader_rec_u;
  549. void *shader_rec_v;
  550. uint32_t shader_rec_p;
  551. uint32_t shader_rec_size;
  552. /* Pointers to the uniform data. These pointers are incremented, and
  553. * size decremented, as each batch of uniforms is uploaded.
  554. */
  555. void *uniforms_u;
  556. void *uniforms_v;
  557. uint32_t uniforms_p;
  558. uint32_t uniforms_size;
  559. /* Pointer to a performance monitor object if the user requested it,
  560. * NULL otherwise.
  561. */
  562. struct vc4_perfmon *perfmon;
  563. /* Whether the exec has taken a reference to the binner BO, which should
  564. * happen with a VC4_PACKET_TILE_BINNING_MODE_CONFIG packet.
  565. */
  566. bool bin_bo_used;
  567. };
  568. /* Per-open file private data. Any driver-specific resource that has to be
  569. * released when the DRM file is closed should be placed here.
  570. */
  571. struct vc4_file {
  572. struct vc4_dev *dev;
  573. struct {
  574. struct idr idr;
  575. struct mutex lock;
  576. } perfmon;
  577. bool bin_bo_used;
  578. };
  579. static inline struct vc4_exec_info *
  580. vc4_first_bin_job(struct vc4_dev *vc4)
  581. {
  582. return list_first_entry_or_null(&vc4->bin_job_list,
  583. struct vc4_exec_info, head);
  584. }
  585. static inline struct vc4_exec_info *
  586. vc4_first_render_job(struct vc4_dev *vc4)
  587. {
  588. return list_first_entry_or_null(&vc4->render_job_list,
  589. struct vc4_exec_info, head);
  590. }
  591. static inline struct vc4_exec_info *
  592. vc4_last_render_job(struct vc4_dev *vc4)
  593. {
  594. if (list_empty(&vc4->render_job_list))
  595. return NULL;
  596. return list_last_entry(&vc4->render_job_list,
  597. struct vc4_exec_info, head);
  598. }
  599. /**
  600. * struct vc4_texture_sample_info - saves the offsets into the UBO for texture
  601. * setup parameters.
  602. *
  603. * This will be used at draw time to relocate the reference to the texture
  604. * contents in p0, and validate that the offset combined with
  605. * width/height/stride/etc. from p1 and p2/p3 doesn't sample outside the BO.
  606. * Note that the hardware treats unprovided config parameters as 0, so not all
  607. * of them need to be set up for every texure sample, and we'll store ~0 as
  608. * the offset to mark the unused ones.
  609. *
  610. * See the VC4 3D architecture guide page 41 ("Texture and Memory Lookup Unit
  611. * Setup") for definitions of the texture parameters.
  612. */
  613. struct vc4_texture_sample_info {
  614. bool is_direct;
  615. uint32_t p_offset[4];
  616. };
  617. /**
  618. * struct vc4_validated_shader_info - information about validated shaders that
  619. * needs to be used from command list validation.
  620. *
  621. * For a given shader, each time a shader state record references it, we need
  622. * to verify that the shader doesn't read more uniforms than the shader state
  623. * record's uniform BO pointer can provide, and we need to apply relocations
  624. * and validate the shader state record's uniforms that define the texture
  625. * samples.
  626. */
  627. struct vc4_validated_shader_info {
  628. uint32_t uniforms_size;
  629. uint32_t uniforms_src_size;
  630. uint32_t num_texture_samples;
  631. struct vc4_texture_sample_info *texture_samples;
  632. uint32_t num_uniform_addr_offsets;
  633. uint32_t *uniform_addr_offsets;
  634. bool is_threaded;
  635. };
  636. /**
  637. * __wait_for - magic wait macro
  638. *
  639. * Macro to help avoid open coding check/wait/timeout patterns. Note that it's
  640. * important that we check the condition again after having timed out, since the
  641. * timeout could be due to preemption or similar and we've never had a chance to
  642. * check the condition before the timeout.
  643. */
  644. #define __wait_for(OP, COND, US, Wmin, Wmax) ({ \
  645. const ktime_t end__ = ktime_add_ns(ktime_get_raw(), 1000ll * (US)); \
  646. long wait__ = (Wmin); /* recommended min for usleep is 10 us */ \
  647. int ret__; \
  648. might_sleep(); \
  649. for (;;) { \
  650. const bool expired__ = ktime_after(ktime_get_raw(), end__); \
  651. OP; \
  652. /* Guarantee COND check prior to timeout */ \
  653. barrier(); \
  654. if (COND) { \
  655. ret__ = 0; \
  656. break; \
  657. } \
  658. if (expired__) { \
  659. ret__ = -ETIMEDOUT; \
  660. break; \
  661. } \
  662. usleep_range(wait__, wait__ * 2); \
  663. if (wait__ < (Wmax)) \
  664. wait__ <<= 1; \
  665. } \
  666. ret__; \
  667. })
  668. #define _wait_for(COND, US, Wmin, Wmax) __wait_for(, (COND), (US), (Wmin), \
  669. (Wmax))
  670. #define wait_for(COND, MS) _wait_for((COND), (MS) * 1000, 10, 1000)
  671. /* vc4_bo.c */
  672. struct drm_gem_object *vc4_create_object(struct drm_device *dev, size_t size);
  673. struct vc4_bo *vc4_bo_create(struct drm_device *dev, size_t size,
  674. bool from_cache, enum vc4_kernel_bo_type type);
  675. int vc4_bo_dumb_create(struct drm_file *file_priv,
  676. struct drm_device *dev,
  677. struct drm_mode_create_dumb *args);
  678. int vc4_create_bo_ioctl(struct drm_device *dev, void *data,
  679. struct drm_file *file_priv);
  680. int vc4_create_shader_bo_ioctl(struct drm_device *dev, void *data,
  681. struct drm_file *file_priv);
  682. int vc4_mmap_bo_ioctl(struct drm_device *dev, void *data,
  683. struct drm_file *file_priv);
  684. int vc4_set_tiling_ioctl(struct drm_device *dev, void *data,
  685. struct drm_file *file_priv);
  686. int vc4_get_tiling_ioctl(struct drm_device *dev, void *data,
  687. struct drm_file *file_priv);
  688. int vc4_get_hang_state_ioctl(struct drm_device *dev, void *data,
  689. struct drm_file *file_priv);
  690. int vc4_label_bo_ioctl(struct drm_device *dev, void *data,
  691. struct drm_file *file_priv);
  692. int vc4_bo_cache_init(struct drm_device *dev);
  693. int vc4_bo_inc_usecnt(struct vc4_bo *bo);
  694. void vc4_bo_dec_usecnt(struct vc4_bo *bo);
  695. void vc4_bo_add_to_purgeable_pool(struct vc4_bo *bo);
  696. void vc4_bo_remove_from_purgeable_pool(struct vc4_bo *bo);
  697. int vc4_bo_debugfs_init(struct drm_minor *minor);
  698. /* vc4_crtc.c */
  699. extern struct platform_driver vc4_crtc_driver;
  700. int vc4_crtc_disable_at_boot(struct drm_crtc *crtc);
  701. int vc4_crtc_init(struct drm_device *drm, struct vc4_crtc *vc4_crtc,
  702. const struct drm_crtc_funcs *crtc_funcs,
  703. const struct drm_crtc_helper_funcs *crtc_helper_funcs);
  704. int vc4_page_flip(struct drm_crtc *crtc,
  705. struct drm_framebuffer *fb,
  706. struct drm_pending_vblank_event *event,
  707. uint32_t flags,
  708. struct drm_modeset_acquire_ctx *ctx);
  709. struct drm_crtc_state *vc4_crtc_duplicate_state(struct drm_crtc *crtc);
  710. void vc4_crtc_destroy_state(struct drm_crtc *crtc,
  711. struct drm_crtc_state *state);
  712. void vc4_crtc_reset(struct drm_crtc *crtc);
  713. void vc4_crtc_handle_vblank(struct vc4_crtc *crtc);
  714. void vc4_crtc_send_vblank(struct drm_crtc *crtc);
  715. int vc4_crtc_late_register(struct drm_crtc *crtc);
  716. void vc4_crtc_get_margins(struct drm_crtc_state *state,
  717. unsigned int *left, unsigned int *right,
  718. unsigned int *top, unsigned int *bottom);
  719. /* vc4_debugfs.c */
  720. void vc4_debugfs_init(struct drm_minor *minor);
  721. #ifdef CONFIG_DEBUG_FS
  722. int vc4_debugfs_add_file(struct drm_minor *minor,
  723. const char *filename,
  724. int (*show)(struct seq_file*, void*),
  725. void *data);
  726. int vc4_debugfs_add_regset32(struct drm_minor *minor,
  727. const char *filename,
  728. struct debugfs_regset32 *regset);
  729. #else
  730. static inline int vc4_debugfs_add_file(struct drm_minor *minor,
  731. const char *filename,
  732. int (*show)(struct seq_file*, void*),
  733. void *data)
  734. {
  735. return 0;
  736. }
  737. static inline int vc4_debugfs_add_regset32(struct drm_minor *minor,
  738. const char *filename,
  739. struct debugfs_regset32 *regset)
  740. {
  741. return 0;
  742. }
  743. #endif
  744. /* vc4_drv.c */
  745. void __iomem *vc4_ioremap_regs(struct platform_device *dev, int index);
  746. int vc4_dumb_fixup_args(struct drm_mode_create_dumb *args);
  747. /* vc4_dpi.c */
  748. extern struct platform_driver vc4_dpi_driver;
  749. /* vc4_dsi.c */
  750. extern struct platform_driver vc4_dsi_driver;
  751. /* vc4_fence.c */
  752. extern const struct dma_fence_ops vc4_fence_ops;
  753. /* vc4_gem.c */
  754. int vc4_gem_init(struct drm_device *dev);
  755. int vc4_submit_cl_ioctl(struct drm_device *dev, void *data,
  756. struct drm_file *file_priv);
  757. int vc4_wait_seqno_ioctl(struct drm_device *dev, void *data,
  758. struct drm_file *file_priv);
  759. int vc4_wait_bo_ioctl(struct drm_device *dev, void *data,
  760. struct drm_file *file_priv);
  761. void vc4_submit_next_bin_job(struct drm_device *dev);
  762. void vc4_submit_next_render_job(struct drm_device *dev);
  763. void vc4_move_job_to_render(struct drm_device *dev, struct vc4_exec_info *exec);
  764. int vc4_wait_for_seqno(struct drm_device *dev, uint64_t seqno,
  765. uint64_t timeout_ns, bool interruptible);
  766. void vc4_job_handle_completed(struct vc4_dev *vc4);
  767. int vc4_queue_seqno_cb(struct drm_device *dev,
  768. struct vc4_seqno_cb *cb, uint64_t seqno,
  769. void (*func)(struct vc4_seqno_cb *cb));
  770. int vc4_gem_madvise_ioctl(struct drm_device *dev, void *data,
  771. struct drm_file *file_priv);
  772. /* vc4_hdmi.c */
  773. extern struct platform_driver vc4_hdmi_driver;
  774. /* vc4_vec.c */
  775. extern struct platform_driver vc4_vec_driver;
  776. /* vc4_txp.c */
  777. extern struct platform_driver vc4_txp_driver;
  778. /* vc4_irq.c */
  779. void vc4_irq_enable(struct drm_device *dev);
  780. void vc4_irq_disable(struct drm_device *dev);
  781. int vc4_irq_install(struct drm_device *dev, int irq);
  782. void vc4_irq_uninstall(struct drm_device *dev);
  783. void vc4_irq_reset(struct drm_device *dev);
  784. /* vc4_hvs.c */
  785. extern struct platform_driver vc4_hvs_driver;
  786. void vc4_hvs_stop_channel(struct vc4_hvs *hvs, unsigned int output);
  787. int vc4_hvs_get_fifo_from_output(struct vc4_hvs *hvs, unsigned int output);
  788. u8 vc4_hvs_get_fifo_frame_count(struct vc4_hvs *hvs, unsigned int fifo);
  789. int vc4_hvs_atomic_check(struct drm_crtc *crtc, struct drm_atomic_state *state);
  790. void vc4_hvs_atomic_begin(struct drm_crtc *crtc, struct drm_atomic_state *state);
  791. void vc4_hvs_atomic_enable(struct drm_crtc *crtc, struct drm_atomic_state *state);
  792. void vc4_hvs_atomic_disable(struct drm_crtc *crtc, struct drm_atomic_state *state);
  793. void vc4_hvs_atomic_flush(struct drm_crtc *crtc, struct drm_atomic_state *state);
  794. void vc4_hvs_dump_state(struct vc4_hvs *hvs);
  795. void vc4_hvs_unmask_underrun(struct vc4_hvs *hvs, int channel);
  796. void vc4_hvs_mask_underrun(struct vc4_hvs *hvs, int channel);
  797. int vc4_hvs_debugfs_init(struct drm_minor *minor);
  798. /* vc4_kms.c */
  799. int vc4_kms_load(struct drm_device *dev);
  800. /* vc4_plane.c */
  801. struct drm_plane *vc4_plane_init(struct drm_device *dev,
  802. enum drm_plane_type type,
  803. uint32_t possible_crtcs);
  804. int vc4_plane_create_additional_planes(struct drm_device *dev);
  805. u32 vc4_plane_write_dlist(struct drm_plane *plane, u32 __iomem *dlist);
  806. u32 vc4_plane_dlist_size(const struct drm_plane_state *state);
  807. void vc4_plane_async_set_fb(struct drm_plane *plane,
  808. struct drm_framebuffer *fb);
  809. /* vc4_v3d.c */
  810. extern struct platform_driver vc4_v3d_driver;
  811. extern const struct of_device_id vc4_v3d_dt_match[];
  812. int vc4_v3d_get_bin_slot(struct vc4_dev *vc4);
  813. int vc4_v3d_bin_bo_get(struct vc4_dev *vc4, bool *used);
  814. void vc4_v3d_bin_bo_put(struct vc4_dev *vc4);
  815. int vc4_v3d_pm_get(struct vc4_dev *vc4);
  816. void vc4_v3d_pm_put(struct vc4_dev *vc4);
  817. int vc4_v3d_debugfs_init(struct drm_minor *minor);
  818. /* vc4_validate.c */
  819. int
  820. vc4_validate_bin_cl(struct drm_device *dev,
  821. void *validated,
  822. void *unvalidated,
  823. struct vc4_exec_info *exec);
  824. int
  825. vc4_validate_shader_recs(struct drm_device *dev, struct vc4_exec_info *exec);
  826. struct drm_gem_dma_object *vc4_use_bo(struct vc4_exec_info *exec,
  827. uint32_t hindex);
  828. int vc4_get_rcl(struct drm_device *dev, struct vc4_exec_info *exec);
  829. bool vc4_check_tex_size(struct vc4_exec_info *exec,
  830. struct drm_gem_dma_object *fbo,
  831. uint32_t offset, uint8_t tiling_format,
  832. uint32_t width, uint32_t height, uint8_t cpp);
  833. /* vc4_validate_shader.c */
  834. struct vc4_validated_shader_info *
  835. vc4_validate_shader(struct drm_gem_dma_object *shader_obj);
  836. /* vc4_perfmon.c */
  837. void vc4_perfmon_get(struct vc4_perfmon *perfmon);
  838. void vc4_perfmon_put(struct vc4_perfmon *perfmon);
  839. void vc4_perfmon_start(struct vc4_dev *vc4, struct vc4_perfmon *perfmon);
  840. void vc4_perfmon_stop(struct vc4_dev *vc4, struct vc4_perfmon *perfmon,
  841. bool capture);
  842. struct vc4_perfmon *vc4_perfmon_find(struct vc4_file *vc4file, int id);
  843. void vc4_perfmon_open_file(struct vc4_file *vc4file);
  844. void vc4_perfmon_close_file(struct vc4_file *vc4file);
  845. int vc4_perfmon_create_ioctl(struct drm_device *dev, void *data,
  846. struct drm_file *file_priv);
  847. int vc4_perfmon_destroy_ioctl(struct drm_device *dev, void *data,
  848. struct drm_file *file_priv);
  849. int vc4_perfmon_get_values_ioctl(struct drm_device *dev, void *data,
  850. struct drm_file *file_priv);
  851. #endif /* _VC4_DRV_H_ */