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> */
5 #ifndef __PANFROST_DEVICE_H__
6 #define __PANFROST_DEVICE_H__
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>
15 struct panfrost_device
;
17 struct panfrost_job_slot
;
19 struct panfrost_perfcnt
;
21 #define NUM_JOB_SLOTS 3
23 struct panfrost_features
{
41 u32 thread_max_workgroup_sz
;
42 u32 thread_max_barrier_sz
;
43 u32 coherency_features
;
44 u32 texture_features
[4];
50 unsigned long hw_features
[64 / BITS_PER_LONG
];
51 unsigned long hw_issues
[64 / BITS_PER_LONG
];
54 struct panfrost_device
{
56 struct drm_device
*ddev
;
57 struct platform_device
*pdev
;
61 struct clk
*bus_clock
;
62 struct regulator
*regulator
;
63 struct reset_control
*rstc
;
65 struct panfrost_features features
;
68 unsigned long as_in_use_mask
;
69 unsigned long as_alloc_mask
;
70 struct list_head as_lru_list
;
72 struct panfrost_job_slot
*js
;
74 struct panfrost_job
*jobs
[NUM_JOB_SLOTS
];
75 struct list_head scheduled_jobs
;
77 struct panfrost_perfcnt
*perfcnt
;
79 struct mutex sched_lock
;
80 struct mutex reset_lock
;
82 struct mutex shrinker_lock
;
83 struct list_head shrinker_list
;
84 struct shrinker shrinker
;
87 struct devfreq
*devfreq
;
88 struct thermal_cooling_device
*cooling
;
91 ktime_t time_last_update
;
97 struct io_pgtable_cfg pgtbl_cfg
;
98 struct io_pgtable_ops
*pgtbl_ops
;
101 struct list_head list
;
104 struct panfrost_file_priv
{
105 struct panfrost_device
*pfdev
;
107 struct drm_sched_entity sched_entity
[NUM_JOB_SLOTS
];
109 struct panfrost_mmu mmu
;
114 static inline struct panfrost_device
*to_panfrost_device(struct drm_device
*ddev
)
116 return ddev
->dev_private
;
119 static inline int panfrost_model_cmp(struct panfrost_device
*pfdev
, s32 id
)
121 s32 match_id
= pfdev
->features
.id
;
123 if (match_id
& 0xf000)
125 return match_id
- id
;
128 static inline bool panfrost_model_is_bifrost(struct panfrost_device
*pfdev
)
130 return panfrost_model_cmp(pfdev
, 0x1000) >= 0;
133 static inline bool panfrost_model_eq(struct panfrost_device
*pfdev
, s32 id
)
135 return !panfrost_model_cmp(pfdev
, id
);
138 int panfrost_unstable_ioctl_check(void);
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
);
144 int panfrost_device_resume(struct device
*dev
);
145 int panfrost_device_suspend(struct device
*dev
);
147 const char *panfrost_exception_name(struct panfrost_device
*pfdev
, u32 exception_code
);