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_device { 55 struct device *dev; 56 struct drm_device *ddev; 57 struct platform_device *pdev; 58 59 void __iomem *iomem; 60 struct clk *clock; 61 struct clk *bus_clock; 62 struct regulator *regulator; 63 struct reset_control *rstc; 64 65 struct panfrost_features features; 66 67 spinlock_t as_lock; 68 unsigned long as_in_use_mask; 69 unsigned long as_alloc_mask; 70 struct list_head as_lru_list; 71 72 struct panfrost_job_slot *js; 73 74 struct panfrost_job *jobs[NUM_JOB_SLOTS]; 75 struct list_head scheduled_jobs; 76 77 struct panfrost_perfcnt *perfcnt; 78 79 struct mutex sched_lock; 80 struct mutex reset_lock; 81 82 struct mutex shrinker_lock; 83 struct list_head shrinker_list; 84 struct shrinker shrinker; 85 86 struct { 87 struct devfreq *devfreq; 88 struct thermal_cooling_device *cooling; 89 ktime_t busy_time; 90 ktime_t idle_time; 91 ktime_t time_last_update; 92 atomic_t busy_count; 93 } devfreq; 94 }; 95 96 struct panfrost_mmu { 97 struct io_pgtable_cfg pgtbl_cfg; 98 struct io_pgtable_ops *pgtbl_ops; 99 int as; 100 atomic_t as_count; 101 struct list_head list; 102 }; 103 104 struct panfrost_file_priv { 105 struct panfrost_device *pfdev; 106 107 struct drm_sched_entity sched_entity[NUM_JOB_SLOTS]; 108 109 struct panfrost_mmu mmu; 110 struct drm_mm mm; 111 spinlock_t mm_lock; 112 }; 113 114 static inline struct panfrost_device *to_panfrost_device(struct drm_device *ddev) 115 { 116 return ddev->dev_private; 117 } 118 119 static inline int panfrost_model_cmp(struct panfrost_device *pfdev, s32 id) 120 { 121 s32 match_id = pfdev->features.id; 122 123 if (match_id & 0xf000) 124 match_id &= 0xf00f; 125 return match_id - id; 126 } 127 128 static inline bool panfrost_model_is_bifrost(struct panfrost_device *pfdev) 129 { 130 return panfrost_model_cmp(pfdev, 0x1000) >= 0; 131 } 132 133 static inline bool panfrost_model_eq(struct panfrost_device *pfdev, s32 id) 134 { 135 return !panfrost_model_cmp(pfdev, id); 136 } 137 138 int panfrost_unstable_ioctl_check(void); 139 140 int panfrost_device_init(struct panfrost_device *pfdev); 141 void panfrost_device_fini(struct panfrost_device *pfdev); 142 void panfrost_device_reset(struct panfrost_device *pfdev); 143 144 int panfrost_device_resume(struct device *dev); 145 int panfrost_device_suspend(struct device *dev); 146 147 const char *panfrost_exception_name(struct panfrost_device *pfdev, u32 exception_code); 148 149 #endif 150