Merge tag 'block-5.11-2021-01-10' of git://git.kernel.dk/linux-block
[linux/fpc-iii.git] / drivers / gpu / drm / lima / lima_device.h
blob41b9d7b4bcc7a0128adda97379b6048735310096
1 /* SPDX-License-Identifier: GPL-2.0 OR MIT */
2 /* Copyright 2018-2019 Qiang Yu <yuq825@gmail.com> */
4 #ifndef __LIMA_DEVICE_H__
5 #define __LIMA_DEVICE_H__
7 #include <drm/drm_device.h>
8 #include <linux/delay.h>
9 #include <linux/list.h>
10 #include <linux/mutex.h>
12 #include "lima_sched.h"
13 #include "lima_dump.h"
14 #include "lima_devfreq.h"
16 enum lima_gpu_id {
17 lima_gpu_mali400 = 0,
18 lima_gpu_mali450,
19 lima_gpu_num,
22 enum lima_ip_id {
23 lima_ip_pmu,
24 lima_ip_gpmmu,
25 lima_ip_ppmmu0,
26 lima_ip_ppmmu1,
27 lima_ip_ppmmu2,
28 lima_ip_ppmmu3,
29 lima_ip_ppmmu4,
30 lima_ip_ppmmu5,
31 lima_ip_ppmmu6,
32 lima_ip_ppmmu7,
33 lima_ip_gp,
34 lima_ip_pp0,
35 lima_ip_pp1,
36 lima_ip_pp2,
37 lima_ip_pp3,
38 lima_ip_pp4,
39 lima_ip_pp5,
40 lima_ip_pp6,
41 lima_ip_pp7,
42 lima_ip_l2_cache0,
43 lima_ip_l2_cache1,
44 lima_ip_l2_cache2,
45 lima_ip_dlbu,
46 lima_ip_bcast,
47 lima_ip_pp_bcast,
48 lima_ip_ppmmu_bcast,
49 lima_ip_num,
52 struct lima_device;
54 struct lima_ip {
55 struct lima_device *dev;
56 enum lima_ip_id id;
57 bool present;
59 void __iomem *iomem;
60 int irq;
62 union {
63 /* gp/pp */
64 bool async_reset;
65 /* l2 cache */
66 spinlock_t lock;
67 /* pmu/bcast */
68 u32 mask;
69 } data;
72 enum lima_pipe_id {
73 lima_pipe_gp,
74 lima_pipe_pp,
75 lima_pipe_num,
78 struct lima_device {
79 struct device *dev;
80 struct drm_device *ddev;
82 enum lima_gpu_id id;
83 u32 gp_version;
84 u32 pp_version;
85 int num_pp;
87 void __iomem *iomem;
88 struct clk *clk_bus;
89 struct clk *clk_gpu;
90 struct reset_control *reset;
91 struct regulator *regulator;
93 struct lima_ip ip[lima_ip_num];
94 struct lima_sched_pipe pipe[lima_pipe_num];
96 struct lima_vm *empty_vm;
97 uint64_t va_start;
98 uint64_t va_end;
100 u32 *dlbu_cpu;
101 dma_addr_t dlbu_dma;
103 struct lima_devfreq devfreq;
105 /* debug info */
106 struct lima_dump_head dump;
107 struct list_head error_task_list;
108 struct mutex error_task_list_lock;
111 static inline struct lima_device *
112 to_lima_dev(struct drm_device *dev)
114 return dev->dev_private;
117 int lima_device_init(struct lima_device *ldev);
118 void lima_device_fini(struct lima_device *ldev);
120 const char *lima_ip_name(struct lima_ip *ip);
122 typedef int (*lima_poll_func_t)(struct lima_ip *);
124 static inline int lima_poll_timeout(struct lima_ip *ip, lima_poll_func_t func,
125 int sleep_us, int timeout_us)
127 ktime_t timeout = ktime_add_us(ktime_get(), timeout_us);
129 might_sleep_if(sleep_us);
130 while (1) {
131 if (func(ip))
132 return 0;
134 if (timeout_us && ktime_compare(ktime_get(), timeout) > 0)
135 return -ETIMEDOUT;
137 if (sleep_us)
138 usleep_range((sleep_us >> 2) + 1, sleep_us);
140 return 0;
143 int lima_device_suspend(struct device *dev);
144 int lima_device_resume(struct device *dev);
146 #endif