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 5 #ifndef __PANFROST_DEVICE_H__ 6 #define __PANFROST_DEVICE_H__ 7 8 #include <linux/atomic.h> 9 #include <linux/io-pgtable.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 15 struct panfrost_device; 16 struct panfrost_mmu; 17 struct panfrost_job_slot; 18 struct panfrost_job; 19 struct panfrost_perfcnt; 20 21 #define NUM_JOB_SLOTS 3 22 23 struct panfrost_features { 24 u16 id; 25 u16 revision; 26 27 u64 shader_present; 28 u64 tiler_present; 29 u64 l2_present; 30 u64 stack_present; 31 u32 as_present; 32 u32 js_present; 33 34 u32 l2_features; 35 u32 core_features; 36 u32 tiler_features; 37 u32 mem_features; 38 u32 mmu_features; 39 u32 thread_features; 40 u32 max_threads; 41 u32 thread_max_workgroup_sz; 42 u32 thread_max_barrier_sz; 43 u32 coherency_features; 44 u32 texture_features[4]; 45 u32 js_features[16]; 46 47 u32 nr_core_groups; 48 u32 thread_tls_alloc; 49 50 unsigned long hw_features[64 / BITS_PER_LONG]; 51 unsigned long hw_issues[64 / BITS_PER_LONG]; 52 }; 53 54 struct panfrost_devfreq_slot { 55 ktime_t busy_time; 56 ktime_t idle_time; 57 ktime_t time_last_update; 58 bool busy; 59 }; 60 61 struct panfrost_device { 62 struct device *dev; 63 struct drm_device *ddev; 64 struct platform_device *pdev; 65 66 void __iomem *iomem; 67 struct clk *clock; 68 struct clk *bus_clock; 69 struct regulator *regulator; 70 struct reset_control *rstc; 71 72 struct panfrost_features features; 73 74 spinlock_t as_lock; 75 unsigned long as_in_use_mask; 76 unsigned long as_alloc_mask; 77 struct list_head as_lru_list; 78 79 struct panfrost_job_slot *js; 80 81 struct panfrost_job *jobs[NUM_JOB_SLOTS]; 82 struct list_head scheduled_jobs; 83 84 struct panfrost_perfcnt *perfcnt; 85 86 struct mutex sched_lock; 87 struct mutex reset_lock; 88 89 struct mutex shrinker_lock; 90 struct list_head shrinker_list; 91 struct shrinker shrinker; 92 93 struct { 94 struct devfreq *devfreq; 95 struct thermal_cooling_device *cooling; 96 unsigned long cur_freq; 97 unsigned long cur_volt; 98 struct panfrost_devfreq_slot slot[NUM_JOB_SLOTS]; 99 } devfreq; 100 }; 101 102 struct panfrost_mmu { 103 struct io_pgtable_cfg pgtbl_cfg; 104 struct io_pgtable_ops *pgtbl_ops; 105 int as; 106 atomic_t as_count; 107 struct list_head list; 108 }; 109 110 struct panfrost_file_priv { 111 struct panfrost_device *pfdev; 112 113 struct drm_sched_entity sched_entity[NUM_JOB_SLOTS]; 114 115 struct panfrost_mmu mmu; 116 struct drm_mm mm; 117 spinlock_t mm_lock; 118 }; 119 120 static inline struct panfrost_device *to_panfrost_device(struct drm_device *ddev) 121 { 122 return ddev->dev_private; 123 } 124 125 static inline int panfrost_model_cmp(struct panfrost_device *pfdev, s32 id) 126 { 127 s32 match_id = pfdev->features.id; 128 129 if (match_id & 0xf000) 130 match_id &= 0xf00f; 131 return match_id - id; 132 } 133 134 static inline bool panfrost_model_is_bifrost(struct panfrost_device *pfdev) 135 { 136 return panfrost_model_cmp(pfdev, 0x1000) >= 0; 137 } 138 139 static inline bool panfrost_model_eq(struct panfrost_device *pfdev, s32 id) 140 { 141 return !panfrost_model_cmp(pfdev, id); 142 } 143 144 int panfrost_unstable_ioctl_check(void); 145 146 int panfrost_device_init(struct panfrost_device *pfdev); 147 void panfrost_device_fini(struct panfrost_device *pfdev); 148 void panfrost_device_reset(struct panfrost_device *pfdev); 149 150 int panfrost_device_resume(struct device *dev); 151 int panfrost_device_suspend(struct device *dev); 152 153 const char *panfrost_exception_name(struct panfrost_device *pfdev, u32 exception_code); 154 155 #endif 156