etnaviv_gpu.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Copyright (C) 2015-2018 Etnaviv Project
  4. */
  5. #ifndef __ETNAVIV_GPU_H__
  6. #define __ETNAVIV_GPU_H__
  7. #include <linux/clk.h>
  8. #include <linux/regulator/consumer.h>
  9. #include "etnaviv_cmdbuf.h"
  10. #include "etnaviv_drv.h"
  11. struct etnaviv_gem_submit;
  12. struct etnaviv_vram_mapping;
  13. struct etnaviv_chip_identity {
  14. /* Chip model. */
  15. u32 model;
  16. /* Revision value.*/
  17. u32 revision;
  18. /* Supported feature fields. */
  19. u32 features;
  20. /* Supported minor feature fields. */
  21. u32 minor_features0;
  22. u32 minor_features1;
  23. u32 minor_features2;
  24. u32 minor_features3;
  25. u32 minor_features4;
  26. u32 minor_features5;
  27. u32 minor_features6;
  28. u32 minor_features7;
  29. u32 minor_features8;
  30. u32 minor_features9;
  31. u32 minor_features10;
  32. u32 minor_features11;
  33. /* Number of streams supported. */
  34. u32 stream_count;
  35. /* Total number of temporary registers per thread. */
  36. u32 register_max;
  37. /* Maximum number of threads. */
  38. u32 thread_count;
  39. /* Number of shader cores. */
  40. u32 shader_core_count;
  41. /* Size of the vertex cache. */
  42. u32 vertex_cache_size;
  43. /* Number of entries in the vertex output buffer. */
  44. u32 vertex_output_buffer_size;
  45. /* Number of pixel pipes. */
  46. u32 pixel_pipes;
  47. /* Number of instructions. */
  48. u32 instruction_count;
  49. /* Number of constants. */
  50. u32 num_constants;
  51. /* Buffer size */
  52. u32 buffer_size;
  53. /* Number of varyings */
  54. u8 varyings_count;
  55. };
  56. enum etnaviv_sec_mode {
  57. ETNA_SEC_NONE = 0,
  58. ETNA_SEC_KERNEL,
  59. ETNA_SEC_TZ
  60. };
  61. struct etnaviv_event {
  62. struct dma_fence *fence;
  63. struct etnaviv_gem_submit *submit;
  64. void (*sync_point)(struct etnaviv_gpu *gpu, struct etnaviv_event *event);
  65. };
  66. struct etnaviv_cmdbuf_suballoc;
  67. struct etnaviv_cmdbuf;
  68. #define ETNA_NR_EVENTS 30
  69. struct etnaviv_gpu {
  70. struct drm_device *drm;
  71. struct thermal_cooling_device *cooling;
  72. struct device *dev;
  73. struct mutex lock;
  74. struct etnaviv_chip_identity identity;
  75. enum etnaviv_sec_mode sec_mode;
  76. struct etnaviv_file_private *lastctx;
  77. struct workqueue_struct *wq;
  78. struct drm_gpu_scheduler sched;
  79. /* 'ring'-buffer: */
  80. struct etnaviv_cmdbuf buffer;
  81. int exec_state;
  82. /* bus base address of memory */
  83. u32 memory_base;
  84. /* event management: */
  85. DECLARE_BITMAP(event_bitmap, ETNA_NR_EVENTS);
  86. struct etnaviv_event event[ETNA_NR_EVENTS];
  87. struct completion event_free;
  88. spinlock_t event_spinlock;
  89. u32 idle_mask;
  90. /* Fencing support */
  91. struct mutex fence_lock;
  92. struct idr fence_idr;
  93. u32 next_fence;
  94. u32 active_fence;
  95. u32 completed_fence;
  96. wait_queue_head_t fence_event;
  97. u64 fence_context;
  98. spinlock_t fence_spinlock;
  99. /* worker for handling 'sync' points: */
  100. struct work_struct sync_point_work;
  101. int sync_point_event;
  102. /* hang detection */
  103. u32 hangcheck_dma_addr;
  104. void __iomem *mmio;
  105. int irq;
  106. struct etnaviv_iommu *mmu;
  107. struct etnaviv_cmdbuf_suballoc *cmdbuf_suballoc;
  108. unsigned int flush_seq;
  109. /* Power Control: */
  110. struct clk *clk_bus;
  111. struct clk *clk_reg;
  112. struct clk *clk_core;
  113. struct clk *clk_shader;
  114. unsigned int freq_scale;
  115. unsigned long base_rate_core;
  116. unsigned long base_rate_shader;
  117. };
  118. static inline void gpu_write(struct etnaviv_gpu *gpu, u32 reg, u32 data)
  119. {
  120. writel(data, gpu->mmio + reg);
  121. }
  122. static inline u32 gpu_read(struct etnaviv_gpu *gpu, u32 reg)
  123. {
  124. return readl(gpu->mmio + reg);
  125. }
  126. static inline bool fence_completed(struct etnaviv_gpu *gpu, u32 fence)
  127. {
  128. return fence_after_eq(gpu->completed_fence, fence);
  129. }
  130. int etnaviv_gpu_get_param(struct etnaviv_gpu *gpu, u32 param, u64 *value);
  131. int etnaviv_gpu_init(struct etnaviv_gpu *gpu);
  132. bool etnaviv_fill_identity_from_hwdb(struct etnaviv_gpu *gpu);
  133. #ifdef CONFIG_DEBUG_FS
  134. int etnaviv_gpu_debugfs(struct etnaviv_gpu *gpu, struct seq_file *m);
  135. #endif
  136. void etnaviv_gpu_recover_hang(struct etnaviv_gpu *gpu);
  137. void etnaviv_gpu_retire(struct etnaviv_gpu *gpu);
  138. int etnaviv_gpu_wait_fence_interruptible(struct etnaviv_gpu *gpu,
  139. u32 fence, struct timespec *timeout);
  140. int etnaviv_gpu_wait_obj_inactive(struct etnaviv_gpu *gpu,
  141. struct etnaviv_gem_object *etnaviv_obj, struct timespec *timeout);
  142. struct dma_fence *etnaviv_gpu_submit(struct etnaviv_gem_submit *submit);
  143. int etnaviv_gpu_pm_get_sync(struct etnaviv_gpu *gpu);
  144. void etnaviv_gpu_pm_put(struct etnaviv_gpu *gpu);
  145. int etnaviv_gpu_wait_idle(struct etnaviv_gpu *gpu, unsigned int timeout_ms);
  146. void etnaviv_gpu_start_fe(struct etnaviv_gpu *gpu, u32 address, u16 prefetch);
  147. extern struct platform_driver etnaviv_gpu_driver;
  148. #endif /* __ETNAVIV_GPU_H__ */