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/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> 15 16struct panfrost_device; 17struct panfrost_mmu; 18struct panfrost_job_slot; 19struct panfrost_job; 20struct panfrost_perfcnt; 21 22#define NUM_JOB_SLOTS 3 23#define MAX_REGULATORS 2 24#define MAX_PM_DOMAINS 3 25 26struct panfrost_features { 27 u16 id; 28 u16 revision; 29 30 u64 shader_present; 31 u64 tiler_present; 32 u64 l2_present; 33 u64 stack_present; 34 u32 as_present; 35 u32 js_present; 36 37 u32 l2_features; 38 u32 core_features; 39 u32 tiler_features; 40 u32 mem_features; 41 u32 mmu_features; 42 u32 thread_features; 43 u32 max_threads; 44 u32 thread_max_workgroup_sz; 45 u32 thread_max_barrier_sz; 46 u32 coherency_features; 47 u32 texture_features[4]; 48 u32 js_features[16]; 49 50 u32 nr_core_groups; 51 u32 thread_tls_alloc; 52 53 unsigned long hw_features[64 / BITS_PER_LONG]; 54 unsigned long hw_issues[64 / BITS_PER_LONG]; 55}; 56 57/* 58 * Features that cannot be automatically detected and need matching using the 59 * compatible string, typically SoC-specific. 60 */ 61struct panfrost_compatible { 62 /* Supplies count and names. */ 63 int num_supplies; 64 const char * const *supply_names; 65 /* 66 * Number of power domains required, note that values 0 and 1 are 67 * handled identically, as only values > 1 need special handling. 68 */ 69 int num_pm_domains; 70 /* Only required if num_pm_domains > 1. */ 71 const char * const *pm_domain_names; 72}; 73 74struct panfrost_device { 75 struct device *dev; 76 struct drm_device *ddev; 77 struct platform_device *pdev; 78 79 void __iomem *iomem; 80 struct clk *clock; 81 struct clk *bus_clock; 82 struct regulator_bulk_data regulators[MAX_REGULATORS]; 83 struct reset_control *rstc; 84 /* pm_domains for devices with more than one. */ 85 struct device *pm_domain_devs[MAX_PM_DOMAINS]; 86 struct device_link *pm_domain_links[MAX_PM_DOMAINS]; 87 88 struct panfrost_features features; 89 const struct panfrost_compatible *comp; 90 91 spinlock_t as_lock; 92 unsigned long as_in_use_mask; 93 unsigned long as_alloc_mask; 94 struct list_head as_lru_list; 95 96 struct panfrost_job_slot *js; 97 98 struct panfrost_job *jobs[NUM_JOB_SLOTS]; 99 struct list_head scheduled_jobs; 100 101 struct panfrost_perfcnt *perfcnt; 102 103 struct mutex sched_lock; 104 struct mutex reset_lock; 105 106 struct mutex shrinker_lock; 107 struct list_head shrinker_list; 108 struct shrinker shrinker; 109 110 struct { 111 struct devfreq *devfreq; 112 struct thermal_cooling_device *cooling; 113 ktime_t busy_time; 114 ktime_t idle_time; 115 ktime_t time_last_update; 116 atomic_t busy_count; 117 } devfreq; 118}; 119 120struct panfrost_mmu { 121 struct io_pgtable_cfg pgtbl_cfg; 122 struct io_pgtable_ops *pgtbl_ops; 123 int as; 124 atomic_t as_count; 125 struct list_head list; 126}; 127 128struct panfrost_file_priv { 129 struct panfrost_device *pfdev; 130 131 struct drm_sched_entity sched_entity[NUM_JOB_SLOTS]; 132 133 struct panfrost_mmu mmu; 134 struct drm_mm mm; 135 spinlock_t mm_lock; 136}; 137 138static inline struct panfrost_device *to_panfrost_device(struct drm_device *ddev) 139{ 140 return ddev->dev_private; 141} 142 143static inline int panfrost_model_cmp(struct panfrost_device *pfdev, s32 id) 144{ 145 s32 match_id = pfdev->features.id; 146 147 if (match_id & 0xf000) 148 match_id &= 0xf00f; 149 return match_id - id; 150} 151 152static inline bool panfrost_model_is_bifrost(struct panfrost_device *pfdev) 153{ 154 return panfrost_model_cmp(pfdev, 0x1000) >= 0; 155} 156 157static inline bool panfrost_model_eq(struct panfrost_device *pfdev, s32 id) 158{ 159 return !panfrost_model_cmp(pfdev, id); 160} 161 162int panfrost_unstable_ioctl_check(void); 163 164int panfrost_device_init(struct panfrost_device *pfdev); 165void panfrost_device_fini(struct panfrost_device *pfdev); 166void panfrost_device_reset(struct panfrost_device *pfdev); 167 168int panfrost_device_resume(struct device *dev); 169int panfrost_device_suspend(struct device *dev); 170 171const char *panfrost_exception_name(struct panfrost_device *pfdev, u32 exception_code); 172 173#endif 174