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