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