panfrost_device.h 7.7 KB

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