panfrost_device.h 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /* Copyright 2018 Marty E. Plummer <hanetzer@startmail.com> */
  3. /* Copyright 2019 Linaro, Ltd, Rob Herring <robh@kernel.org> */
  4. #ifndef __PANFROST_DEVICE_H__
  5. #define __PANFROST_DEVICE_H__
  6. #include <linux/atomic.h>
  7. #include <linux/io-pgtable.h>
  8. #include <linux/pm.h>
  9. #include <linux/regulator/consumer.h>
  10. #include <linux/spinlock.h>
  11. #include <drm/drm_device.h>
  12. #include <drm/drm_mm.h>
  13. #include <drm/gpu_scheduler.h>
  14. #include "panfrost_devfreq.h"
  15. struct panfrost_device;
  16. struct panfrost_mmu;
  17. struct panfrost_job_slot;
  18. struct panfrost_job;
  19. struct panfrost_perfcnt;
  20. #define NUM_JOB_SLOTS 3
  21. #define MAX_PM_DOMAINS 5
  22. enum panfrost_drv_comp_bits {
  23. PANFROST_COMP_BIT_GPU,
  24. PANFROST_COMP_BIT_JOB,
  25. PANFROST_COMP_BIT_MMU,
  26. PANFROST_COMP_BIT_MAX
  27. };
  28. /**
  29. * enum panfrost_gpu_pm - Supported kernel power management features
  30. * @GPU_PM_CLK_DIS: Allow disabling clocks during system suspend
  31. * @GPU_PM_VREG_OFF: Allow turning off regulators during system suspend
  32. */
  33. enum panfrost_gpu_pm {
  34. GPU_PM_CLK_DIS,
  35. GPU_PM_VREG_OFF,
  36. };
  37. struct panfrost_features {
  38. u16 id;
  39. u16 revision;
  40. u64 shader_present;
  41. u64 tiler_present;
  42. u64 l2_present;
  43. u64 stack_present;
  44. u32 as_present;
  45. u32 js_present;
  46. u32 l2_features;
  47. u32 core_features;
  48. u32 tiler_features;
  49. u32 mem_features;
  50. u32 mmu_features;
  51. u32 thread_features;
  52. u32 max_threads;
  53. u32 thread_max_workgroup_sz;
  54. u32 thread_max_barrier_sz;
  55. u32 coherency_features;
  56. u32 afbc_features;
  57. u32 texture_features[4];
  58. u32 js_features[16];
  59. u32 nr_core_groups;
  60. u32 thread_tls_alloc;
  61. unsigned long hw_features[64 / BITS_PER_LONG];
  62. unsigned long hw_issues[64 / BITS_PER_LONG];
  63. };
  64. /*
  65. * Features that cannot be automatically detected and need matching using the
  66. * compatible string, typically SoC-specific.
  67. */
  68. struct panfrost_compatible {
  69. /* Supplies count and names. */
  70. int num_supplies;
  71. const char * const *supply_names;
  72. /*
  73. * Number of power domains required, note that values 0 and 1 are
  74. * handled identically, as only values > 1 need special handling.
  75. */
  76. int num_pm_domains;
  77. /* Only required if num_pm_domains > 1. */
  78. const char * const *pm_domain_names;
  79. /* Vendor implementation quirks callback */
  80. void (*vendor_quirk)(struct panfrost_device *pfdev);
  81. /* Allowed PM features */
  82. u8 pm_features;
  83. };
  84. struct panfrost_device {
  85. struct device *dev;
  86. struct drm_device *ddev;
  87. struct platform_device *pdev;
  88. int gpu_irq;
  89. int mmu_irq;
  90. void __iomem *iomem;
  91. struct clk *clock;
  92. struct clk *bus_clock;
  93. struct regulator_bulk_data *regulators;
  94. struct reset_control *rstc;
  95. /* pm_domains for devices with more than one. */
  96. struct device *pm_domain_devs[MAX_PM_DOMAINS];
  97. struct device_link *pm_domain_links[MAX_PM_DOMAINS];
  98. bool coherent;
  99. struct panfrost_features features;
  100. const struct panfrost_compatible *comp;
  101. DECLARE_BITMAP(is_suspended, PANFROST_COMP_BIT_MAX);
  102. spinlock_t as_lock;
  103. unsigned long as_in_use_mask;
  104. unsigned long as_alloc_mask;
  105. unsigned long as_faulty_mask;
  106. struct list_head as_lru_list;
  107. struct panfrost_job_slot *js;
  108. struct panfrost_job *jobs[NUM_JOB_SLOTS][2];
  109. struct list_head scheduled_jobs;
  110. struct panfrost_perfcnt *perfcnt;
  111. bool profile_mode;
  112. struct mutex sched_lock;
  113. struct {
  114. struct workqueue_struct *wq;
  115. struct work_struct work;
  116. atomic_t pending;
  117. } reset;
  118. struct mutex shrinker_lock;
  119. struct list_head shrinker_list;
  120. struct shrinker *shrinker;
  121. struct panfrost_devfreq pfdevfreq;
  122. struct {
  123. atomic_t use_count;
  124. spinlock_t lock;
  125. } cycle_counter;
  126. };
  127. struct panfrost_mmu {
  128. struct panfrost_device *pfdev;
  129. struct kref refcount;
  130. struct io_pgtable_cfg pgtbl_cfg;
  131. struct io_pgtable_ops *pgtbl_ops;
  132. struct drm_mm mm;
  133. spinlock_t mm_lock;
  134. int as;
  135. atomic_t as_count;
  136. struct list_head list;
  137. };
  138. struct panfrost_engine_usage {
  139. unsigned long long elapsed_ns[NUM_JOB_SLOTS];
  140. unsigned long long cycles[NUM_JOB_SLOTS];
  141. };
  142. struct panfrost_file_priv {
  143. struct panfrost_device *pfdev;
  144. struct drm_sched_entity sched_entity[NUM_JOB_SLOTS];
  145. struct panfrost_mmu *mmu;
  146. struct panfrost_engine_usage engine_usage;
  147. };
  148. static inline struct panfrost_device *to_panfrost_device(struct drm_device *ddev)
  149. {
  150. return ddev->dev_private;
  151. }
  152. static inline int panfrost_model_cmp(struct panfrost_device *pfdev, s32 id)
  153. {
  154. s32 match_id = pfdev->features.id;
  155. if (match_id & 0xf000)
  156. match_id &= 0xf00f;
  157. return match_id - id;
  158. }
  159. static inline bool panfrost_model_is_bifrost(struct panfrost_device *pfdev)
  160. {
  161. return panfrost_model_cmp(pfdev, 0x1000) >= 0;
  162. }
  163. static inline bool panfrost_model_eq(struct panfrost_device *pfdev, s32 id)
  164. {
  165. return !panfrost_model_cmp(pfdev, id);
  166. }
  167. int panfrost_unstable_ioctl_check(void);
  168. int panfrost_device_init(struct panfrost_device *pfdev);
  169. void panfrost_device_fini(struct panfrost_device *pfdev);
  170. void panfrost_device_reset(struct panfrost_device *pfdev);
  171. extern const struct dev_pm_ops panfrost_pm_ops;
  172. enum drm_panfrost_exception_type {
  173. DRM_PANFROST_EXCEPTION_OK = 0x00,
  174. DRM_PANFROST_EXCEPTION_DONE = 0x01,
  175. DRM_PANFROST_EXCEPTION_INTERRUPTED = 0x02,
  176. DRM_PANFROST_EXCEPTION_STOPPED = 0x03,
  177. DRM_PANFROST_EXCEPTION_TERMINATED = 0x04,
  178. DRM_PANFROST_EXCEPTION_KABOOM = 0x05,
  179. DRM_PANFROST_EXCEPTION_EUREKA = 0x06,
  180. DRM_PANFROST_EXCEPTION_ACTIVE = 0x08,
  181. DRM_PANFROST_EXCEPTION_MAX_NON_FAULT = 0x3f,
  182. DRM_PANFROST_EXCEPTION_JOB_CONFIG_FAULT = 0x40,
  183. DRM_PANFROST_EXCEPTION_JOB_POWER_FAULT = 0x41,
  184. DRM_PANFROST_EXCEPTION_JOB_READ_FAULT = 0x42,
  185. DRM_PANFROST_EXCEPTION_JOB_WRITE_FAULT = 0x43,
  186. DRM_PANFROST_EXCEPTION_JOB_AFFINITY_FAULT = 0x44,
  187. DRM_PANFROST_EXCEPTION_JOB_BUS_FAULT = 0x48,
  188. DRM_PANFROST_EXCEPTION_INSTR_INVALID_PC = 0x50,
  189. DRM_PANFROST_EXCEPTION_INSTR_INVALID_ENC = 0x51,
  190. DRM_PANFROST_EXCEPTION_INSTR_TYPE_MISMATCH = 0x52,
  191. DRM_PANFROST_EXCEPTION_INSTR_OPERAND_FAULT = 0x53,
  192. DRM_PANFROST_EXCEPTION_INSTR_TLS_FAULT = 0x54,
  193. DRM_PANFROST_EXCEPTION_INSTR_BARRIER_FAULT = 0x55,
  194. DRM_PANFROST_EXCEPTION_INSTR_ALIGN_FAULT = 0x56,
  195. DRM_PANFROST_EXCEPTION_DATA_INVALID_FAULT = 0x58,
  196. DRM_PANFROST_EXCEPTION_TILE_RANGE_FAULT = 0x59,
  197. DRM_PANFROST_EXCEPTION_ADDR_RANGE_FAULT = 0x5a,
  198. DRM_PANFROST_EXCEPTION_IMPRECISE_FAULT = 0x5b,
  199. DRM_PANFROST_EXCEPTION_OOM = 0x60,
  200. DRM_PANFROST_EXCEPTION_OOM_AFBC = 0x61,
  201. DRM_PANFROST_EXCEPTION_UNKNOWN = 0x7f,
  202. DRM_PANFROST_EXCEPTION_DELAYED_BUS_FAULT = 0x80,
  203. DRM_PANFROST_EXCEPTION_GPU_SHAREABILITY_FAULT = 0x88,
  204. DRM_PANFROST_EXCEPTION_SYS_SHAREABILITY_FAULT = 0x89,
  205. DRM_PANFROST_EXCEPTION_GPU_CACHEABILITY_FAULT = 0x8a,
  206. DRM_PANFROST_EXCEPTION_TRANSLATION_FAULT_0 = 0xc0,
  207. DRM_PANFROST_EXCEPTION_TRANSLATION_FAULT_1 = 0xc1,
  208. DRM_PANFROST_EXCEPTION_TRANSLATION_FAULT_2 = 0xc2,
  209. DRM_PANFROST_EXCEPTION_TRANSLATION_FAULT_3 = 0xc3,
  210. DRM_PANFROST_EXCEPTION_TRANSLATION_FAULT_4 = 0xc4,
  211. DRM_PANFROST_EXCEPTION_TRANSLATION_FAULT_IDENTITY = 0xc7,
  212. DRM_PANFROST_EXCEPTION_PERM_FAULT_0 = 0xc8,
  213. DRM_PANFROST_EXCEPTION_PERM_FAULT_1 = 0xc9,
  214. DRM_PANFROST_EXCEPTION_PERM_FAULT_2 = 0xca,
  215. DRM_PANFROST_EXCEPTION_PERM_FAULT_3 = 0xcb,
  216. DRM_PANFROST_EXCEPTION_TRANSTAB_BUS_FAULT_0 = 0xd0,
  217. DRM_PANFROST_EXCEPTION_TRANSTAB_BUS_FAULT_1 = 0xd1,
  218. DRM_PANFROST_EXCEPTION_TRANSTAB_BUS_FAULT_2 = 0xd2,
  219. DRM_PANFROST_EXCEPTION_TRANSTAB_BUS_FAULT_3 = 0xd3,
  220. DRM_PANFROST_EXCEPTION_ACCESS_FLAG_0 = 0xd8,
  221. DRM_PANFROST_EXCEPTION_ACCESS_FLAG_1 = 0xd9,
  222. DRM_PANFROST_EXCEPTION_ACCESS_FLAG_2 = 0xda,
  223. DRM_PANFROST_EXCEPTION_ACCESS_FLAG_3 = 0xdb,
  224. DRM_PANFROST_EXCEPTION_ADDR_SIZE_FAULT_IN0 = 0xe0,
  225. DRM_PANFROST_EXCEPTION_ADDR_SIZE_FAULT_IN1 = 0xe1,
  226. DRM_PANFROST_EXCEPTION_ADDR_SIZE_FAULT_IN2 = 0xe2,
  227. DRM_PANFROST_EXCEPTION_ADDR_SIZE_FAULT_IN3 = 0xe3,
  228. DRM_PANFROST_EXCEPTION_ADDR_SIZE_FAULT_OUT0 = 0xe4,
  229. DRM_PANFROST_EXCEPTION_ADDR_SIZE_FAULT_OUT1 = 0xe5,
  230. DRM_PANFROST_EXCEPTION_ADDR_SIZE_FAULT_OUT2 = 0xe6,
  231. DRM_PANFROST_EXCEPTION_ADDR_SIZE_FAULT_OUT3 = 0xe7,
  232. DRM_PANFROST_EXCEPTION_MEM_ATTR_FAULT_0 = 0xe8,
  233. DRM_PANFROST_EXCEPTION_MEM_ATTR_FAULT_1 = 0xe9,
  234. DRM_PANFROST_EXCEPTION_MEM_ATTR_FAULT_2 = 0xea,
  235. DRM_PANFROST_EXCEPTION_MEM_ATTR_FAULT_3 = 0xeb,
  236. DRM_PANFROST_EXCEPTION_MEM_ATTR_NONCACHE_0 = 0xec,
  237. DRM_PANFROST_EXCEPTION_MEM_ATTR_NONCACHE_1 = 0xed,
  238. DRM_PANFROST_EXCEPTION_MEM_ATTR_NONCACHE_2 = 0xee,
  239. DRM_PANFROST_EXCEPTION_MEM_ATTR_NONCACHE_3 = 0xef,
  240. };
  241. static inline bool
  242. panfrost_exception_is_fault(u32 exception_code)
  243. {
  244. return exception_code > DRM_PANFROST_EXCEPTION_MAX_NON_FAULT;
  245. }
  246. const char *panfrost_exception_name(u32 exception_code);
  247. bool panfrost_exception_needs_reset(const struct panfrost_device *pfdev,
  248. u32 exception_code);
  249. static inline void
  250. panfrost_device_schedule_reset(struct panfrost_device *pfdev)
  251. {
  252. atomic_set(&pfdev->reset.pending, 1);
  253. queue_work(pfdev->reset.wq, &pfdev->reset.work);
  254. }
  255. #endif