Rob Herring | f3ba912 | 2018-09-10 14:27:58 -0500 | [diff] [blame] | 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 | |
Rob Herring | 7282f76 | 2019-08-13 09:01:15 -0600 | [diff] [blame] | 8 | #include <linux/atomic.h> |
| 9 | #include <linux/io-pgtable.h> |
Nicolas Boichat | 3e1399b | 2020-02-07 13:26:24 +0800 | [diff] [blame] | 10 | #include <linux/regulator/consumer.h> |
Rob Herring | f3ba912 | 2018-09-10 14:27:58 -0500 | [diff] [blame] | 11 | #include <linux/spinlock.h> |
| 12 | #include <drm/drm_device.h> |
| 13 | #include <drm/drm_mm.h> |
| 14 | #include <drm/gpu_scheduler.h> |
| 15 | |
Clément Péron | 9bfacfc | 2020-07-10 11:53:59 +0200 | [diff] [blame] | 16 | #include "panfrost_devfreq.h" |
| 17 | |
Rob Herring | f3ba912 | 2018-09-10 14:27:58 -0500 | [diff] [blame] | 18 | struct panfrost_device; |
| 19 | struct panfrost_mmu; |
| 20 | struct panfrost_job_slot; |
| 21 | struct panfrost_job; |
Boris Brezillon | 7786fd1 | 2019-06-18 10:16:48 +0200 | [diff] [blame] | 22 | struct panfrost_perfcnt; |
Rob Herring | f3ba912 | 2018-09-10 14:27:58 -0500 | [diff] [blame] | 23 | |
| 24 | #define NUM_JOB_SLOTS 3 |
Nicolas Boichat | 506629c | 2020-02-07 13:26:25 +0800 | [diff] [blame] | 25 | #define MAX_PM_DOMAINS 3 |
Rob Herring | f3ba912 | 2018-09-10 14:27:58 -0500 | [diff] [blame] | 26 | |
| 27 | struct panfrost_features { |
| 28 | u16 id; |
| 29 | u16 revision; |
| 30 | |
| 31 | u64 shader_present; |
| 32 | u64 tiler_present; |
| 33 | u64 l2_present; |
| 34 | u64 stack_present; |
| 35 | u32 as_present; |
| 36 | u32 js_present; |
| 37 | |
| 38 | u32 l2_features; |
| 39 | u32 core_features; |
| 40 | u32 tiler_features; |
| 41 | u32 mem_features; |
| 42 | u32 mmu_features; |
| 43 | u32 thread_features; |
| 44 | u32 max_threads; |
| 45 | u32 thread_max_workgroup_sz; |
| 46 | u32 thread_max_barrier_sz; |
| 47 | u32 coherency_features; |
| 48 | u32 texture_features[4]; |
| 49 | u32 js_features[16]; |
| 50 | |
| 51 | u32 nr_core_groups; |
Steven Price | 4bced8b | 2019-07-24 11:56:26 +0100 | [diff] [blame] | 52 | u32 thread_tls_alloc; |
Rob Herring | f3ba912 | 2018-09-10 14:27:58 -0500 | [diff] [blame] | 53 | |
| 54 | unsigned long hw_features[64 / BITS_PER_LONG]; |
| 55 | unsigned long hw_issues[64 / BITS_PER_LONG]; |
| 56 | }; |
| 57 | |
Nicolas Boichat | 3e1399b | 2020-02-07 13:26:24 +0800 | [diff] [blame] | 58 | /* |
| 59 | * Features that cannot be automatically detected and need matching using the |
| 60 | * compatible string, typically SoC-specific. |
| 61 | */ |
| 62 | struct panfrost_compatible { |
| 63 | /* Supplies count and names. */ |
| 64 | int num_supplies; |
| 65 | const char * const *supply_names; |
Nicolas Boichat | 506629c | 2020-02-07 13:26:25 +0800 | [diff] [blame] | 66 | /* |
| 67 | * Number of power domains required, note that values 0 and 1 are |
| 68 | * handled identically, as only values > 1 need special handling. |
| 69 | */ |
| 70 | int num_pm_domains; |
| 71 | /* Only required if num_pm_domains > 1. */ |
| 72 | const char * const *pm_domain_names; |
Neil Armstrong | 91e8909 | 2020-09-16 17:01:45 +0200 | [diff] [blame] | 73 | |
| 74 | /* Vendor implementation quirks callback */ |
| 75 | void (*vendor_quirk)(struct panfrost_device *pfdev); |
Nicolas Boichat | 3e1399b | 2020-02-07 13:26:24 +0800 | [diff] [blame] | 76 | }; |
| 77 | |
Rob Herring | f3ba912 | 2018-09-10 14:27:58 -0500 | [diff] [blame] | 78 | struct panfrost_device { |
| 79 | struct device *dev; |
| 80 | struct drm_device *ddev; |
| 81 | struct platform_device *pdev; |
| 82 | |
Rob Herring | f3ba912 | 2018-09-10 14:27:58 -0500 | [diff] [blame] | 83 | void __iomem *iomem; |
| 84 | struct clk *clock; |
Clément Péron | b681af0 | 2019-05-21 18:10:57 +0200 | [diff] [blame] | 85 | struct clk *bus_clock; |
Clément Péron | 512f2122 | 2020-07-10 11:54:04 +0200 | [diff] [blame] | 86 | struct regulator_bulk_data *regulators; |
Rob Herring | f3ba912 | 2018-09-10 14:27:58 -0500 | [diff] [blame] | 87 | struct reset_control *rstc; |
Nicolas Boichat | 506629c | 2020-02-07 13:26:25 +0800 | [diff] [blame] | 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]; |
Robin Murphy | 268af50 | 2020-09-22 15:16:49 +0100 | [diff] [blame^] | 91 | bool coherent; |
Rob Herring | f3ba912 | 2018-09-10 14:27:58 -0500 | [diff] [blame] | 92 | |
| 93 | struct panfrost_features features; |
Nicolas Boichat | 3e1399b | 2020-02-07 13:26:24 +0800 | [diff] [blame] | 94 | const struct panfrost_compatible *comp; |
Rob Herring | f3ba912 | 2018-09-10 14:27:58 -0500 | [diff] [blame] | 95 | |
Rob Herring | 7282f76 | 2019-08-13 09:01:15 -0600 | [diff] [blame] | 96 | spinlock_t as_lock; |
| 97 | unsigned long as_in_use_mask; |
| 98 | unsigned long as_alloc_mask; |
| 99 | struct list_head as_lru_list; |
| 100 | |
Rob Herring | f3ba912 | 2018-09-10 14:27:58 -0500 | [diff] [blame] | 101 | struct panfrost_job_slot *js; |
| 102 | |
| 103 | struct panfrost_job *jobs[NUM_JOB_SLOTS]; |
| 104 | struct list_head scheduled_jobs; |
| 105 | |
Boris Brezillon | 7786fd1 | 2019-06-18 10:16:48 +0200 | [diff] [blame] | 106 | struct panfrost_perfcnt *perfcnt; |
| 107 | |
Rob Herring | f3ba912 | 2018-09-10 14:27:58 -0500 | [diff] [blame] | 108 | struct mutex sched_lock; |
Tomeu Vizoso | aa20236 | 2019-04-18 10:41:48 +0200 | [diff] [blame] | 109 | struct mutex reset_lock; |
Rob Herring | f3ba912 | 2018-09-10 14:27:58 -0500 | [diff] [blame] | 110 | |
Rob Herring | 013b65101 | 2019-08-05 08:33:58 -0600 | [diff] [blame] | 111 | struct mutex shrinker_lock; |
| 112 | struct list_head shrinker_list; |
| 113 | struct shrinker shrinker; |
| 114 | |
Clément Péron | 9bfacfc | 2020-07-10 11:53:59 +0200 | [diff] [blame] | 115 | struct panfrost_devfreq pfdevfreq; |
Rob Herring | f3ba912 | 2018-09-10 14:27:58 -0500 | [diff] [blame] | 116 | }; |
| 117 | |
Rob Herring | 7282f76 | 2019-08-13 09:01:15 -0600 | [diff] [blame] | 118 | struct panfrost_mmu { |
| 119 | struct io_pgtable_cfg pgtbl_cfg; |
| 120 | struct io_pgtable_ops *pgtbl_ops; |
Rob Herring | 7282f76 | 2019-08-13 09:01:15 -0600 | [diff] [blame] | 121 | int as; |
| 122 | atomic_t as_count; |
| 123 | struct list_head list; |
| 124 | }; |
| 125 | |
Rob Herring | f3ba912 | 2018-09-10 14:27:58 -0500 | [diff] [blame] | 126 | struct panfrost_file_priv { |
| 127 | struct panfrost_device *pfdev; |
| 128 | |
| 129 | struct drm_sched_entity sched_entity[NUM_JOB_SLOTS]; |
Rob Herring | 7282f76 | 2019-08-13 09:01:15 -0600 | [diff] [blame] | 130 | |
| 131 | struct panfrost_mmu mmu; |
| 132 | struct drm_mm mm; |
| 133 | spinlock_t mm_lock; |
Rob Herring | f3ba912 | 2018-09-10 14:27:58 -0500 | [diff] [blame] | 134 | }; |
| 135 | |
| 136 | static inline struct panfrost_device *to_panfrost_device(struct drm_device *ddev) |
| 137 | { |
| 138 | return ddev->dev_private; |
| 139 | } |
| 140 | |
| 141 | static inline int panfrost_model_cmp(struct panfrost_device *pfdev, s32 id) |
| 142 | { |
| 143 | s32 match_id = pfdev->features.id; |
| 144 | |
| 145 | if (match_id & 0xf000) |
| 146 | match_id &= 0xf00f; |
| 147 | return match_id - id; |
| 148 | } |
| 149 | |
Boris Brezillon | 1e51348 | 2019-06-18 10:16:47 +0200 | [diff] [blame] | 150 | static inline bool panfrost_model_is_bifrost(struct panfrost_device *pfdev) |
| 151 | { |
| 152 | return panfrost_model_cmp(pfdev, 0x1000) >= 0; |
| 153 | } |
| 154 | |
Rob Herring | f3ba912 | 2018-09-10 14:27:58 -0500 | [diff] [blame] | 155 | static inline bool panfrost_model_eq(struct panfrost_device *pfdev, s32 id) |
| 156 | { |
| 157 | return !panfrost_model_cmp(pfdev, id); |
| 158 | } |
| 159 | |
Boris Brezillon | 92f0ad0 | 2019-06-18 10:16:46 +0200 | [diff] [blame] | 160 | int panfrost_unstable_ioctl_check(void); |
| 161 | |
Rob Herring | f3ba912 | 2018-09-10 14:27:58 -0500 | [diff] [blame] | 162 | int panfrost_device_init(struct panfrost_device *pfdev); |
| 163 | void panfrost_device_fini(struct panfrost_device *pfdev); |
Rob Herring | 73e467f | 2019-08-08 14:30:39 -0600 | [diff] [blame] | 164 | void panfrost_device_reset(struct panfrost_device *pfdev); |
Rob Herring | f3ba912 | 2018-09-10 14:27:58 -0500 | [diff] [blame] | 165 | |
| 166 | int panfrost_device_resume(struct device *dev); |
| 167 | int panfrost_device_suspend(struct device *dev); |
| 168 | |
| 169 | const char *panfrost_exception_name(struct panfrost_device *pfdev, u32 exception_code); |
| 170 | |
| 171 | #endif |