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/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;
48 u32 texture_features[4];
54 unsigned long hw_features[64 / BITS_PER_LONG];
55 unsigned long hw_issues[64 / BITS_PER_LONG];
59 * Features that cannot be automatically detected and need matching using the
60 * compatible string, typically SoC-specific.
62 struct panfrost_compatible {
63 /* Supplies count and names. */
65 const char * const *supply_names;
67 * Number of power domains required, note that values 0 and 1 are
68 * handled identically, as only values > 1 need special handling.
71 /* Only required if num_pm_domains > 1. */
72 const char * const *pm_domain_names;
74 /* Vendor implementation quirks callback */
75 void (*vendor_quirk)(struct panfrost_device *pfdev);
78 struct panfrost_device {
80 struct drm_device *ddev;
81 struct platform_device *pdev;
85 struct clk *bus_clock;
86 struct regulator_bulk_data *regulators;
87 struct reset_control *rstc;
88 /* pm_domains for devices with more than one. */
89 struct device *pm_domain_devs[MAX_PM_DOMAINS];
90 struct device_link *pm_domain_links[MAX_PM_DOMAINS];
93 struct panfrost_features features;
94 const struct panfrost_compatible *comp;
97 unsigned long as_in_use_mask;
98 unsigned long as_alloc_mask;
99 struct list_head as_lru_list;
101 struct panfrost_job_slot *js;
103 struct panfrost_job *jobs[NUM_JOB_SLOTS];
104 struct list_head scheduled_jobs;
106 struct panfrost_perfcnt *perfcnt;
108 struct mutex sched_lock;
111 struct work_struct work;
115 struct mutex shrinker_lock;
116 struct list_head shrinker_list;
117 struct shrinker shrinker;
119 struct panfrost_devfreq pfdevfreq;
122 struct panfrost_mmu {
123 struct panfrost_device *pfdev;
124 struct kref refcount;
125 struct io_pgtable_cfg pgtbl_cfg;
126 struct io_pgtable_ops *pgtbl_ops;
131 struct list_head list;
134 struct panfrost_file_priv {
135 struct panfrost_device *pfdev;
137 struct drm_sched_entity sched_entity[NUM_JOB_SLOTS];
139 struct panfrost_mmu *mmu;
142 static inline struct panfrost_device *to_panfrost_device(struct drm_device *ddev)
144 return ddev->dev_private;
147 static inline int panfrost_model_cmp(struct panfrost_device *pfdev, s32 id)
149 s32 match_id = pfdev->features.id;
151 if (match_id & 0xf000)
153 return match_id - id;
156 static inline bool panfrost_model_is_bifrost(struct panfrost_device *pfdev)
158 return panfrost_model_cmp(pfdev, 0x1000) >= 0;
161 static inline bool panfrost_model_eq(struct panfrost_device *pfdev, s32 id)
163 return !panfrost_model_cmp(pfdev, id);
166 int panfrost_unstable_ioctl_check(void);
168 int panfrost_device_init(struct panfrost_device *pfdev);
169 void panfrost_device_fini(struct panfrost_device *pfdev);
170 void panfrost_device_reset(struct panfrost_device *pfdev);
172 int panfrost_device_resume(struct device *dev);
173 int panfrost_device_suspend(struct device *dev);
175 const char *panfrost_exception_name(struct panfrost_device *pfdev, u32 exception_code);