]> asedeno.scripts.mit.edu Git - linux.git/blob - drivers/gpu/drm/panfrost/panfrost_device.h
drm/panfrost: Use generic code for devfreq
[linux.git] / drivers / gpu / drm / panfrost / panfrost_device.h
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                 struct panfrost_devfreq_slot slot[NUM_JOB_SLOTS];
97         } devfreq;
98 };
99
100 struct panfrost_mmu {
101         struct io_pgtable_cfg pgtbl_cfg;
102         struct io_pgtable_ops *pgtbl_ops;
103         int as;
104         atomic_t as_count;
105         struct list_head list;
106 };
107
108 struct panfrost_file_priv {
109         struct panfrost_device *pfdev;
110
111         struct drm_sched_entity sched_entity[NUM_JOB_SLOTS];
112
113         struct panfrost_mmu mmu;
114         struct drm_mm mm;
115         spinlock_t mm_lock;
116 };
117
118 static inline struct panfrost_device *to_panfrost_device(struct drm_device *ddev)
119 {
120         return ddev->dev_private;
121 }
122
123 static inline int panfrost_model_cmp(struct panfrost_device *pfdev, s32 id)
124 {
125         s32 match_id = pfdev->features.id;
126
127         if (match_id & 0xf000)
128                 match_id &= 0xf00f;
129         return match_id - id;
130 }
131
132 static inline bool panfrost_model_is_bifrost(struct panfrost_device *pfdev)
133 {
134         return panfrost_model_cmp(pfdev, 0x1000) >= 0;
135 }
136
137 static inline bool panfrost_model_eq(struct panfrost_device *pfdev, s32 id)
138 {
139         return !panfrost_model_cmp(pfdev, id);
140 }
141
142 int panfrost_unstable_ioctl_check(void);
143
144 int panfrost_device_init(struct panfrost_device *pfdev);
145 void panfrost_device_fini(struct panfrost_device *pfdev);
146 void panfrost_device_reset(struct panfrost_device *pfdev);
147
148 int panfrost_device_resume(struct device *dev);
149 int panfrost_device_suspend(struct device *dev);
150
151 const char *panfrost_exception_name(struct panfrost_device *pfdev, u32 exception_code);
152
153 #endif