blob: ea5948ff364735fe8c8ce657f8ce923d4c0f57b1 [file] [log] [blame]
Rob Herringf3ba9122018-09-10 14:27:58 -05001/* 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
13struct panfrost_device;
14struct panfrost_mmu;
15struct panfrost_job_slot;
16struct panfrost_job;
Boris Brezillon7786fd12019-06-18 10:16:48 +020017struct panfrost_perfcnt;
Rob Herringf3ba9122018-09-10 14:27:58 -050018
19#define NUM_JOB_SLOTS 3
20
21struct 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;
Steven Price4bced8b2019-07-24 11:56:26 +010046 u32 thread_tls_alloc;
Rob Herringf3ba9122018-09-10 14:27:58 -050047
48 unsigned long hw_features[64 / BITS_PER_LONG];
49 unsigned long hw_issues[64 / BITS_PER_LONG];
50};
51
52struct panfrost_devfreq_slot {
53 ktime_t busy_time;
54 ktime_t idle_time;
55 ktime_t time_last_update;
56 bool busy;
57};
58
59struct panfrost_device {
60 struct device *dev;
61 struct drm_device *ddev;
62 struct platform_device *pdev;
63
64 spinlock_t hwaccess_lock;
65
66 struct drm_mm mm;
67 spinlock_t mm_lock;
68
69 void __iomem *iomem;
70 struct clk *clock;
Clément Péronb681af02019-05-21 18:10:57 +020071 struct clk *bus_clock;
Rob Herringf3ba9122018-09-10 14:27:58 -050072 struct regulator *regulator;
73 struct reset_control *rstc;
74
75 struct panfrost_features features;
76
77 struct panfrost_mmu *mmu;
78 struct panfrost_job_slot *js;
79
80 struct panfrost_job *jobs[NUM_JOB_SLOTS];
81 struct list_head scheduled_jobs;
82
Boris Brezillon7786fd12019-06-18 10:16:48 +020083 struct panfrost_perfcnt *perfcnt;
84
Rob Herringf3ba9122018-09-10 14:27:58 -050085 struct mutex sched_lock;
Tomeu Vizosoaa202362019-04-18 10:41:48 +020086 struct mutex reset_lock;
Rob Herringf3ba9122018-09-10 14:27:58 -050087
88 struct {
89 struct devfreq *devfreq;
90 struct thermal_cooling_device *cooling;
91 unsigned long cur_freq;
92 unsigned long cur_volt;
93 struct panfrost_devfreq_slot slot[NUM_JOB_SLOTS];
94 } devfreq;
95};
96
97struct panfrost_file_priv {
98 struct panfrost_device *pfdev;
99
100 struct drm_sched_entity sched_entity[NUM_JOB_SLOTS];
101};
102
103static inline struct panfrost_device *to_panfrost_device(struct drm_device *ddev)
104{
105 return ddev->dev_private;
106}
107
108static inline int panfrost_model_cmp(struct panfrost_device *pfdev, s32 id)
109{
110 s32 match_id = pfdev->features.id;
111
112 if (match_id & 0xf000)
113 match_id &= 0xf00f;
114 return match_id - id;
115}
116
Boris Brezillon1e513482019-06-18 10:16:47 +0200117static inline bool panfrost_model_is_bifrost(struct panfrost_device *pfdev)
118{
119 return panfrost_model_cmp(pfdev, 0x1000) >= 0;
120}
121
Rob Herringf3ba9122018-09-10 14:27:58 -0500122static inline bool panfrost_model_eq(struct panfrost_device *pfdev, s32 id)
123{
124 return !panfrost_model_cmp(pfdev, id);
125}
126
Boris Brezillon92f0ad02019-06-18 10:16:46 +0200127int panfrost_unstable_ioctl_check(void);
128
Rob Herringf3ba9122018-09-10 14:27:58 -0500129int panfrost_device_init(struct panfrost_device *pfdev);
130void panfrost_device_fini(struct panfrost_device *pfdev);
131
132int panfrost_device_resume(struct device *dev);
133int panfrost_device_suspend(struct device *dev);
134
135const char *panfrost_exception_name(struct panfrost_device *pfdev, u32 exception_code);
136
137#endif