1 /* SPDX-License-Identifier: GPL-2.0 */
5 #ifndef __PANFROST_DEVICE_H__
6 #define __PANFROST_DEVICE_H__
8 #include <linux/atomic.h>
9 #include <linux/io-pgtable.h>
10 #include <linux/regulator/consumer.h>
11 #include <linux/spinlock.h>
12 #include <drm/drm_device.h>
13 #include <drm/drm_mm.h>
14 #include <drm/gpu_scheduler.h>
16 #include "panfrost_devfreq.h"
18 struct panfrost_device;
20 struct panfrost_job_slot;
22 struct panfrost_perfcnt;
24 #define NUM_JOB_SLOTS 3
25 #define MAX_PM_DOMAINS 3
27 struct panfrost_features {
45 u32 thread_max_workgroup_sz;
46 u32 thread_max_barrier_sz;
47 u32 coherency_features;
49 u32 texture_features[4];
55 unsigned long hw_features[64 / BITS_PER_LONG];
56 unsigned long hw_issues[64 / BITS_PER_LONG];
60 * Features that cannot be automatically detected and need matching using the
61 * compatible string, typically SoC-specific.
63 struct panfrost_compatible {
64 /* Supplies count and names. */
66 const char * const *supply_names;
68 * Number of power domains required, note that values 0 and 1 are
69 * handled identically, as only values > 1 need special handling.
72 /* Only required if num_pm_domains > 1. */
73 const char * const *pm_domain_names;
75 /* Vendor implementation quirks callback */
76 void (*vendor_quirk)(struct panfrost_device *pfdev);
79 struct panfrost_device {
81 struct drm_device *ddev;
82 struct platform_device *pdev;
86 struct clk *bus_clock;
87 struct regulator_bulk_data *regulators;
88 struct reset_control *rstc;
89 /* pm_domains for devices with more than one. */
90 struct device *pm_domain_devs[MAX_PM_DOMAINS];
91 struct device_link *pm_domain_links[MAX_PM_DOMAINS];
94 struct panfrost_features features;
95 const struct panfrost_compatible *comp;
98 unsigned long as_in_use_mask;
99 unsigned long as_alloc_mask;
100 struct list_head as_lru_list;
102 struct panfrost_job_slot *js;
104 struct panfrost_job *jobs[NUM_JOB_SLOTS];
105 struct list_head scheduled_jobs;
107 struct panfrost_perfcnt *perfcnt;
109 struct mutex sched_lock;
112 struct work_struct work;
116 struct mutex shrinker_lock;
117 struct list_head shrinker_list;
118 struct shrinker shrinker;
120 struct panfrost_devfreq pfdevfreq;
123 struct panfrost_mmu {
124 struct io_pgtable_cfg pgtbl_cfg;
125 struct io_pgtable_ops *pgtbl_ops;
128 struct list_head list;
131 struct panfrost_file_priv {
132 struct panfrost_device *pfdev;
134 struct drm_sched_entity sched_entity[NUM_JOB_SLOTS];
136 struct panfrost_mmu mmu;
141 static inline struct panfrost_device *to_panfrost_device(struct drm_device *ddev)
143 return ddev->dev_private;
146 static inline int panfrost_model_cmp(struct panfrost_device *pfdev, s32 id)
148 s32 match_id = pfdev->features.id;
150 if (match_id & 0xf000)
152 return match_id - id;
155 static inline bool panfrost_model_is_bifrost(struct panfrost_device *pfdev)
157 return panfrost_model_cmp(pfdev, 0x1000) >= 0;
160 static inline bool panfrost_model_eq(struct panfrost_device *pfdev, s32 id)
162 return !panfrost_model_cmp(pfdev, id);
165 int panfrost_unstable_ioctl_check(void);
167 int panfrost_device_init(struct panfrost_device *pfdev);
168 void panfrost_device_fini(struct panfrost_device *pfdev);
169 void panfrost_device_reset(struct panfrost_device *pfdev);
171 int panfrost_device_resume(struct device *dev);
172 int panfrost_device_suspend(struct device *dev);
174 const char *panfrost_exception_name(struct panfrost_device *pfdev, u32 exception_code);