1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3 * Copyright (C) 2013 Red Hat
4 * Author: Rob Clark <robdclark@gmail.com>
5 *
6 * Copyright (c) 2014,2017, 2019 The Linux Foundation. All rights reserved.
7 */
8
9 #ifndef __ADRENO_GPU_H__
10 #define __ADRENO_GPU_H__
11
12 #include <linux/firmware.h>
13 #include <linux/iopoll.h>
14
15 #include <linux/soc/qcom/ubwc.h>
16
17 #include "msm_gpu.h"
18
19 #include "adreno_common.xml.h"
20 #include "adreno_pm4.xml.h"
21
22 extern bool snapshot_debugbus;
23
24 enum {
25 ADRENO_FW_PM4 = 0,
26 ADRENO_FW_SQE = 0, /* a6xx */
27 ADRENO_FW_PFP = 1,
28 ADRENO_FW_GMU = 1, /* a6xx */
29 ADRENO_FW_GPMU = 2,
30 ADRENO_FW_AQE = 3,
31 ADRENO_FW_MAX,
32 };
33
34 /**
35 * @enum adreno_family: identify generation and possibly sub-generation
36 *
37 * In some cases there are distinct sub-generations within a major revision
38 * so it helps to be able to group the GPU devices by generation and if
39 * necessary sub-generation.
40 */
41 enum adreno_family {
42 ADRENO_2XX_GEN1, /* a20x */
43 ADRENO_2XX_GEN2, /* a22x */
44 ADRENO_3XX,
45 ADRENO_4XX,
46 ADRENO_5XX,
47 ADRENO_6XX_GEN1, /* a630 family */
48 ADRENO_6XX_GEN2, /* a640 family */
49 ADRENO_6XX_GEN3, /* a650 family */
50 ADRENO_6XX_GEN4, /* a660 family */
51 ADRENO_7XX_GEN1, /* a730 family */
52 ADRENO_7XX_GEN2, /* a740 family */
53 ADRENO_7XX_GEN3, /* a750 family */
54 ADRENO_8XX_GEN1, /* a830 family */
55 ADRENO_8XX_GEN2, /* a840 family */
56 };
57
58 #define ADRENO_QUIRK_TWO_PASS_USE_WFI BIT(0)
59 #define ADRENO_QUIRK_FAULT_DETECT_MASK BIT(1)
60 #define ADRENO_QUIRK_LMLOADKILL_DISABLE BIT(2)
61 #define ADRENO_QUIRK_HAS_HW_APRIV BIT(3)
62 #define ADRENO_QUIRK_HAS_CACHED_COHERENT BIT(4)
63 #define ADRENO_QUIRK_PREEMPTION BIT(5)
64 #define ADRENO_QUIRK_4GB_VA BIT(6)
65 #define ADRENO_QUIRK_IFPC BIT(7)
66
67 /* Helper for formating the chip_id in the way that userspace tools like
68 * crashdec expect.
69 */
70 #define ADRENO_CHIPID_FMT "u.%u.%u.%u"
71 #define ADRENO_CHIPID_ARGS(_c) \
72 (((_c) >> 24) & 0xff), \
73 (((_c) >> 16) & 0xff), \
74 (((_c) >> 8) & 0xff), \
75 ((_c) & 0xff)
76
77 struct adreno_gpu;
78
79 struct adreno_gpu_funcs {
80 struct msm_gpu_funcs base;
81 struct msm_gpu *(*init)(struct drm_device *dev);
82 int (*get_timestamp)(struct msm_gpu *gpu, uint64_t *value);
83 void (*bus_halt)(struct adreno_gpu *adreno_gpu, bool gx_off);
84 int (*mmu_fault_handler)(void *arg, unsigned long iova, int flags, void *data);
85 };
86
87 struct adreno_reglist {
88 u32 offset;
89 u32 value;
90 };
91
92 /* Reglist with pipe information */
93 struct adreno_reglist_pipe {
94 u32 offset;
95 u32 value;
96 u32 pipe;
97 };
98
99 struct adreno_speedbin {
100 uint16_t fuse;
101 uint16_t speedbin;
102 };
103
104 struct a6xx_info;
105
106 struct adreno_info {
107 const char *machine;
108 /**
109 * @chipids: Table of matching chip-ids
110 *
111 * Terminated with 0 sentinal
112 */
113 uint32_t *chip_ids;
114 enum adreno_family family;
115 uint32_t revn;
116 const char *fw[ADRENO_FW_MAX];
117 uint32_t gmem;
118 u64 quirks;
119 const struct adreno_gpu_funcs *funcs;
120 const char *zapfw;
121 u32 inactive_period;
122 union {
123 const struct a6xx_info *a6xx;
124 };
125 /**
126 * @speedbins: Optional table of fuse to speedbin mappings
127 *
128 * Consists of pairs of fuse, index mappings, terminated with
129 * {SHRT_MAX, 0} sentinal.
130 */
131 struct adreno_speedbin *speedbins;
132 u64 preempt_record_size;
133 };
134
135 #define ADRENO_CHIP_IDS(tbl...) (uint32_t[]) { tbl, 0 }
136
137 struct adreno_gpulist {
138 const struct adreno_info *gpus;
139 unsigned gpus_count;
140 };
141
142 #define DECLARE_ADRENO_GPULIST(name) \
143 const struct adreno_gpulist name ## _gpulist = { \
144 name ## _gpus, ARRAY_SIZE(name ## _gpus) \
145 }
146
147 /*
148 * Helper to build a speedbin table, ie. the table:
149 * fuse | speedbin
150 * -----+---------
151 * 0 | 0
152 * 169 | 1
153 * 174 | 2
154 *
155 * would be declared as:
156 *
157 * .speedbins = ADRENO_SPEEDBINS(
158 * { 0, 0 },
159 * { 169, 1 },
160 * { 174, 2 },
161 * ),
162 */
163 #define ADRENO_SPEEDBINS(tbl...) (struct adreno_speedbin[]) { tbl {SHRT_MAX, 0} }
164
165 struct adreno_protect {
166 const uint32_t *regs;
167 uint32_t count;
168 uint32_t count_max;
169 };
170
171 #define DECLARE_ADRENO_PROTECT(name, __count_max) \
172 static const struct adreno_protect name = { \
173 .regs = name ## _regs, \
174 .count = ARRAY_SIZE(name ## _regs), \
175 .count_max = __count_max, \
176 };
177
178 struct adreno_reglist_list {
179 /** @reg: List of register **/
180 const u32 *regs;
181 /** @count: Number of registers in the list **/
182 u32 count;
183 };
184
185 #define DECLARE_ADRENO_REGLIST_LIST(name) \
186 static const struct adreno_reglist_list name = { \
187 .regs = name ## _regs, \
188 .count = ARRAY_SIZE(name ## _regs), \
189 };
190
191 struct adreno_gpu {
192 struct msm_gpu base;
193 const struct adreno_info *info;
194 uint32_t chip_id;
195 uint16_t speedbin;
196 const struct adreno_gpu_funcs *funcs;
197
198 struct completion fault_coredump_done;
199
200 /* interesting register offsets to dump: */
201 const unsigned int *registers;
202
203 /*
204 * Are we loading fw from legacy path? Prior to addition
205 * of gpu firmware to linux-firmware, the fw files were
206 * placed in toplevel firmware directory, following qcom's
207 * android kernel. But linux-firmware preferred they be
208 * placed in a 'qcom' subdirectory.
209 *
210 * For backwards compatibility, we try first to load from
211 * the new path, using request_firmware_direct() to avoid
212 * any potential timeout waiting for usermode helper, then
213 * fall back to the old path (with direct load). And
214 * finally fall back to request_firmware() with the new
215 * path to allow the usermode helper.
216 */
217 enum {
218 FW_LOCATION_UNKNOWN = 0,
219 FW_LOCATION_NEW, /* /lib/firmware/qcom/$fwfile */
220 FW_LOCATION_LEGACY, /* /lib/firmware/$fwfile */
221 FW_LOCATION_HELPER,
222 } fwloc;
223
224 /* firmware: */
225 const struct firmware *fw[ADRENO_FW_MAX];
226
227 /*
228 * The migration to the central UBWC config db is still in flight - keep
229 * a copy containing some local fixups until that's done.
230 */
231 const struct qcom_ubwc_cfg_data *ubwc_config;
232 struct qcom_ubwc_cfg_data _ubwc_config;
233
234 /*
235 * Register offsets are different between some GPUs.
236 * GPU specific offsets will be exported by GPU specific
237 * code (a3xx_gpu.c) and stored in this common location.
238 */
239 const unsigned int *reg_offsets;
240 bool gmu_is_wrapper;
241
242 bool has_ray_tracing;
243
244 u64 uche_trap_base;
245 };
246 #define to_adreno_gpu(x) container_of(x, struct adreno_gpu, base)
247
248 struct adreno_ocmem {
249 struct ocmem *ocmem;
250 unsigned long base;
251 void *hdl;
252 };
253
254 /* platform config data (ie. from DT, or pdata) */
255 struct adreno_platform_config {
256 uint32_t chip_id;
257 const struct adreno_info *info;
258 };
259
260 #define ADRENO_IDLE_TIMEOUT msecs_to_jiffies(1000)
261
262 #define spin_until(X) ({ \
263 int __ret = -ETIMEDOUT; \
264 unsigned long __t = jiffies + ADRENO_IDLE_TIMEOUT; \
265 do { \
266 if (X) { \
267 __ret = 0; \
268 break; \
269 } \
270 } while (time_before(jiffies, __t)); \
271 __ret; \
272 })
273
adreno_patchid(const struct adreno_gpu * gpu)274 static inline uint8_t adreno_patchid(const struct adreno_gpu *gpu)
275 {
276 /* It is probably ok to assume legacy "adreno_rev" format
277 * for all a6xx devices, but probably best to limit this
278 * to older things.
279 */
280 WARN_ON_ONCE(gpu->info->family >= ADRENO_6XX_GEN1);
281 return gpu->chip_id & 0xff;
282 }
283
adreno_is_revn(const struct adreno_gpu * gpu,uint32_t revn)284 static inline bool adreno_is_revn(const struct adreno_gpu *gpu, uint32_t revn)
285 {
286 if (WARN_ON_ONCE(!gpu->info))
287 return false;
288 return gpu->info->revn == revn;
289 }
290
adreno_has_gmu_wrapper(const struct adreno_gpu * gpu)291 static inline bool adreno_has_gmu_wrapper(const struct adreno_gpu *gpu)
292 {
293 return gpu->gmu_is_wrapper;
294 }
295
adreno_is_a2xx(const struct adreno_gpu * gpu)296 static inline bool adreno_is_a2xx(const struct adreno_gpu *gpu)
297 {
298 if (WARN_ON_ONCE(!gpu->info))
299 return false;
300 return gpu->info->family <= ADRENO_2XX_GEN2;
301 }
302
adreno_is_a20x(const struct adreno_gpu * gpu)303 static inline bool adreno_is_a20x(const struct adreno_gpu *gpu)
304 {
305 if (WARN_ON_ONCE(!gpu->info))
306 return false;
307 return gpu->info->family == ADRENO_2XX_GEN1;
308 }
309
adreno_is_a225(const struct adreno_gpu * gpu)310 static inline bool adreno_is_a225(const struct adreno_gpu *gpu)
311 {
312 return adreno_is_revn(gpu, 225);
313 }
314
adreno_is_a305(const struct adreno_gpu * gpu)315 static inline bool adreno_is_a305(const struct adreno_gpu *gpu)
316 {
317 return adreno_is_revn(gpu, 305);
318 }
319
adreno_is_a305b(const struct adreno_gpu * gpu)320 static inline bool adreno_is_a305b(const struct adreno_gpu *gpu)
321 {
322 return gpu->info->chip_ids[0] == 0x03000512;
323 }
324
adreno_is_a306(const struct adreno_gpu * gpu)325 static inline bool adreno_is_a306(const struct adreno_gpu *gpu)
326 {
327 /* yes, 307, because a305c is 306 */
328 return adreno_is_revn(gpu, 307);
329 }
330
adreno_is_a306a(const struct adreno_gpu * gpu)331 static inline bool adreno_is_a306a(const struct adreno_gpu *gpu)
332 {
333 /* a306a (marketing name is a308) */
334 return adreno_is_revn(gpu, 308);
335 }
336
adreno_is_a320(const struct adreno_gpu * gpu)337 static inline bool adreno_is_a320(const struct adreno_gpu *gpu)
338 {
339 return adreno_is_revn(gpu, 320);
340 }
341
adreno_is_a330(const struct adreno_gpu * gpu)342 static inline bool adreno_is_a330(const struct adreno_gpu *gpu)
343 {
344 return adreno_is_revn(gpu, 330);
345 }
346
adreno_is_a330v2(const struct adreno_gpu * gpu)347 static inline bool adreno_is_a330v2(const struct adreno_gpu *gpu)
348 {
349 return adreno_is_a330(gpu) && (adreno_patchid(gpu) > 0);
350 }
351
adreno_is_a405(const struct adreno_gpu * gpu)352 static inline int adreno_is_a405(const struct adreno_gpu *gpu)
353 {
354 return adreno_is_revn(gpu, 405);
355 }
356
adreno_is_a420(const struct adreno_gpu * gpu)357 static inline int adreno_is_a420(const struct adreno_gpu *gpu)
358 {
359 return adreno_is_revn(gpu, 420);
360 }
361
adreno_is_a430(const struct adreno_gpu * gpu)362 static inline int adreno_is_a430(const struct adreno_gpu *gpu)
363 {
364 return adreno_is_revn(gpu, 430);
365 }
366
adreno_is_a505(const struct adreno_gpu * gpu)367 static inline int adreno_is_a505(const struct adreno_gpu *gpu)
368 {
369 return adreno_is_revn(gpu, 505);
370 }
371
adreno_is_a506(const struct adreno_gpu * gpu)372 static inline int adreno_is_a506(const struct adreno_gpu *gpu)
373 {
374 return adreno_is_revn(gpu, 506);
375 }
376
adreno_is_a508(const struct adreno_gpu * gpu)377 static inline int adreno_is_a508(const struct adreno_gpu *gpu)
378 {
379 return adreno_is_revn(gpu, 508);
380 }
381
adreno_is_a509(const struct adreno_gpu * gpu)382 static inline int adreno_is_a509(const struct adreno_gpu *gpu)
383 {
384 return adreno_is_revn(gpu, 509);
385 }
386
adreno_is_a510(const struct adreno_gpu * gpu)387 static inline int adreno_is_a510(const struct adreno_gpu *gpu)
388 {
389 return adreno_is_revn(gpu, 510);
390 }
391
adreno_is_a512(const struct adreno_gpu * gpu)392 static inline int adreno_is_a512(const struct adreno_gpu *gpu)
393 {
394 return adreno_is_revn(gpu, 512);
395 }
396
adreno_is_a530(const struct adreno_gpu * gpu)397 static inline int adreno_is_a530(const struct adreno_gpu *gpu)
398 {
399 return adreno_is_revn(gpu, 530);
400 }
401
adreno_is_a540(const struct adreno_gpu * gpu)402 static inline int adreno_is_a540(const struct adreno_gpu *gpu)
403 {
404 return adreno_is_revn(gpu, 540);
405 }
406
adreno_is_a610(const struct adreno_gpu * gpu)407 static inline int adreno_is_a610(const struct adreno_gpu *gpu)
408 {
409 return adreno_is_revn(gpu, 610);
410 }
411
adreno_is_a612(const struct adreno_gpu * gpu)412 static inline int adreno_is_a612(const struct adreno_gpu *gpu)
413 {
414 return gpu->info->chip_ids[0] == 0x06010200;
415 }
416
adreno_has_rgmu(const struct adreno_gpu * gpu)417 static inline bool adreno_has_rgmu(const struct adreno_gpu *gpu)
418 {
419 return adreno_is_a612(gpu);
420 }
421
adreno_is_a618(const struct adreno_gpu * gpu)422 static inline int adreno_is_a618(const struct adreno_gpu *gpu)
423 {
424 return adreno_is_revn(gpu, 618);
425 }
426
adreno_is_a619(const struct adreno_gpu * gpu)427 static inline int adreno_is_a619(const struct adreno_gpu *gpu)
428 {
429 return adreno_is_revn(gpu, 619);
430 }
431
adreno_is_a619_holi(const struct adreno_gpu * gpu)432 static inline int adreno_is_a619_holi(const struct adreno_gpu *gpu)
433 {
434 return adreno_is_a619(gpu) && adreno_has_gmu_wrapper(gpu);
435 }
436
adreno_is_a621(const struct adreno_gpu * gpu)437 static inline int adreno_is_a621(const struct adreno_gpu *gpu)
438 {
439 return gpu->info->chip_ids[0] == 0x06020100;
440 }
441
adreno_is_a623(const struct adreno_gpu * gpu)442 static inline int adreno_is_a623(const struct adreno_gpu *gpu)
443 {
444 return gpu->info->chip_ids[0] == 0x06020300;
445 }
446
adreno_is_a630(const struct adreno_gpu * gpu)447 static inline int adreno_is_a630(const struct adreno_gpu *gpu)
448 {
449 return adreno_is_revn(gpu, 630);
450 }
451
adreno_is_a640(const struct adreno_gpu * gpu)452 static inline int adreno_is_a640(const struct adreno_gpu *gpu)
453 {
454 return adreno_is_revn(gpu, 640);
455 }
456
adreno_is_a650(const struct adreno_gpu * gpu)457 static inline int adreno_is_a650(const struct adreno_gpu *gpu)
458 {
459 return adreno_is_revn(gpu, 650);
460 }
461
adreno_is_7c3(const struct adreno_gpu * gpu)462 static inline int adreno_is_7c3(const struct adreno_gpu *gpu)
463 {
464 return gpu->info->chip_ids[0] == 0x06030500;
465 }
466
adreno_is_a660(const struct adreno_gpu * gpu)467 static inline int adreno_is_a660(const struct adreno_gpu *gpu)
468 {
469 return adreno_is_revn(gpu, 660);
470 }
471
adreno_is_a680(const struct adreno_gpu * gpu)472 static inline int adreno_is_a680(const struct adreno_gpu *gpu)
473 {
474 return adreno_is_revn(gpu, 680);
475 }
476
adreno_is_a663(const struct adreno_gpu * gpu)477 static inline int adreno_is_a663(const struct adreno_gpu *gpu)
478 {
479 return gpu->info->chip_ids[0] == 0x06060300;
480 }
481
adreno_is_a690(const struct adreno_gpu * gpu)482 static inline int adreno_is_a690(const struct adreno_gpu *gpu)
483 {
484 return gpu->info->chip_ids[0] == 0x06090000;
485 }
486
adreno_is_a702(const struct adreno_gpu * gpu)487 static inline int adreno_is_a702(const struct adreno_gpu *gpu)
488 {
489 return gpu->info->chip_ids[0] == 0x07000200;
490 }
491
adreno_is_a610_family(const struct adreno_gpu * gpu)492 static inline int adreno_is_a610_family(const struct adreno_gpu *gpu)
493 {
494 if (WARN_ON_ONCE(!gpu->info))
495 return false;
496 return adreno_is_a610(gpu) ||
497 adreno_is_a612(gpu) ||
498 adreno_is_a702(gpu);
499 }
500
501 /* TODO: 615/616 */
adreno_is_a615_family(const struct adreno_gpu * gpu)502 static inline int adreno_is_a615_family(const struct adreno_gpu *gpu)
503 {
504 return adreno_is_a618(gpu) ||
505 adreno_is_a619(gpu);
506 }
507
adreno_is_a630_family(const struct adreno_gpu * gpu)508 static inline int adreno_is_a630_family(const struct adreno_gpu *gpu)
509 {
510 if (WARN_ON_ONCE(!gpu->info))
511 return false;
512 return gpu->info->family == ADRENO_6XX_GEN1;
513 }
514
adreno_is_a660_family(const struct adreno_gpu * gpu)515 static inline int adreno_is_a660_family(const struct adreno_gpu *gpu)
516 {
517 if (WARN_ON_ONCE(!gpu->info))
518 return false;
519 return gpu->info->family == ADRENO_6XX_GEN4;
520 }
521
522 /* check for a650, a660, or any derivatives */
adreno_is_a650_family(const struct adreno_gpu * gpu)523 static inline int adreno_is_a650_family(const struct adreno_gpu *gpu)
524 {
525 if (WARN_ON_ONCE(!gpu->info))
526 return false;
527 return gpu->info->family == ADRENO_6XX_GEN3 ||
528 gpu->info->family == ADRENO_6XX_GEN4;
529 }
530
adreno_is_a640_family(const struct adreno_gpu * gpu)531 static inline int adreno_is_a640_family(const struct adreno_gpu *gpu)
532 {
533 if (WARN_ON_ONCE(!gpu->info))
534 return false;
535 return gpu->info->family == ADRENO_6XX_GEN2;
536 }
537
adreno_is_a730(struct adreno_gpu * gpu)538 static inline int adreno_is_a730(struct adreno_gpu *gpu)
539 {
540 return gpu->info->chip_ids[0] == 0x07030001;
541 }
542
adreno_is_a740(struct adreno_gpu * gpu)543 static inline int adreno_is_a740(struct adreno_gpu *gpu)
544 {
545 return gpu->info->chip_ids[0] == 0x43050a01;
546 }
547
adreno_is_a750(struct adreno_gpu * gpu)548 static inline int adreno_is_a750(struct adreno_gpu *gpu)
549 {
550 return gpu->info->chip_ids[0] == 0x43051401;
551 }
552
adreno_is_x185(struct adreno_gpu * gpu)553 static inline int adreno_is_x185(struct adreno_gpu *gpu)
554 {
555 return gpu->info->chip_ids[0] == 0x43050c01;
556 }
557
adreno_is_a740_family(struct adreno_gpu * gpu)558 static inline int adreno_is_a740_family(struct adreno_gpu *gpu)
559 {
560 if (WARN_ON_ONCE(!gpu->info))
561 return false;
562 return gpu->info->family == ADRENO_7XX_GEN2 ||
563 gpu->info->family == ADRENO_7XX_GEN3;
564 }
565
adreno_is_a750_family(struct adreno_gpu * gpu)566 static inline int adreno_is_a750_family(struct adreno_gpu *gpu)
567 {
568 return gpu->info->family == ADRENO_7XX_GEN3;
569 }
570
adreno_is_a7xx(struct adreno_gpu * gpu)571 static inline int adreno_is_a7xx(struct adreno_gpu *gpu)
572 {
573 /* Update with non-fake (i.e. non-A702) Gen 7 GPUs */
574 return gpu->info->family == ADRENO_7XX_GEN1 ||
575 adreno_is_a740_family(gpu);
576 }
577
adreno_is_a8xx(struct adreno_gpu * gpu)578 static inline int adreno_is_a8xx(struct adreno_gpu *gpu)
579 {
580 return gpu->info->family >= ADRENO_8XX_GEN1;
581 }
582
adreno_is_x285(struct adreno_gpu * gpu)583 static inline int adreno_is_x285(struct adreno_gpu *gpu)
584 {
585 return gpu->info->chip_ids[0] == 0x44070001;
586 }
587
adreno_is_a840(struct adreno_gpu * gpu)588 static inline int adreno_is_a840(struct adreno_gpu *gpu)
589 {
590 return gpu->info->chip_ids[0] == 0x44050a01;
591 }
592
593 /* Put vm_start above 32b to catch issues with not setting xyz_BASE_HI */
594 #define ADRENO_VM_START 0x100000000ULL
595 u64 adreno_private_vm_size(struct msm_gpu *gpu);
596 int adreno_get_param(struct msm_gpu *gpu, struct msm_context *ctx,
597 uint32_t param, uint64_t *value, uint32_t *len);
598 int adreno_set_param(struct msm_gpu *gpu, struct msm_context *ctx,
599 uint32_t param, uint64_t value, uint32_t len);
600 const struct firmware *adreno_request_fw(struct adreno_gpu *adreno_gpu,
601 const char *fwname);
602 struct drm_gem_object *adreno_fw_create_bo(struct msm_gpu *gpu,
603 const struct firmware *fw, u64 *iova);
604 int adreno_hw_init(struct msm_gpu *gpu);
605 void adreno_recover(struct msm_gpu *gpu);
606 void adreno_flush(struct msm_gpu *gpu, struct msm_ringbuffer *ring, u32 reg);
607 bool adreno_idle(struct msm_gpu *gpu, struct msm_ringbuffer *ring);
608 #if defined(CONFIG_DEBUG_FS) || defined(CONFIG_DEV_COREDUMP)
609 void adreno_show(struct msm_gpu *gpu, struct msm_gpu_state *state,
610 struct drm_printer *p);
611 #endif
612 void adreno_dump_info(struct msm_gpu *gpu);
613 void adreno_dump(struct msm_gpu *gpu);
614 void adreno_wait_ring(struct msm_ringbuffer *ring, uint32_t ndwords);
615 struct msm_ringbuffer *adreno_active_ring(struct msm_gpu *gpu);
616
617 int adreno_gpu_ocmem_init(struct device *dev, struct adreno_gpu *adreno_gpu,
618 struct adreno_ocmem *ocmem);
619 void adreno_gpu_ocmem_cleanup(struct adreno_ocmem *ocmem);
620
621 int adreno_gpu_init(struct drm_device *drm, struct platform_device *pdev,
622 struct adreno_gpu *gpu, const struct adreno_gpu_funcs *funcs,
623 int nr_rings);
624 void adreno_gpu_cleanup(struct adreno_gpu *gpu);
625 int adreno_load_fw(struct adreno_gpu *adreno_gpu);
626
627 void adreno_gpu_state_destroy(struct msm_gpu_state *state);
628
629 int adreno_gpu_state_get(struct msm_gpu *gpu, struct msm_gpu_state *state);
630 int adreno_gpu_state_put(struct msm_gpu_state *state);
631 void adreno_show_object(struct drm_printer *p, void **ptr, int len,
632 bool *encoded);
633
634 /*
635 * Common helper function to initialize the default address space for arm-smmu
636 * attached targets
637 */
638 struct drm_gpuvm *
639 adreno_create_vm(struct msm_gpu *gpu,
640 struct platform_device *pdev);
641
642 struct drm_gpuvm *
643 adreno_iommu_create_vm(struct msm_gpu *gpu,
644 struct platform_device *pdev,
645 unsigned long quirks);
646
647 int adreno_fault_handler(struct msm_gpu *gpu, unsigned long iova, int flags,
648 struct adreno_smmu_fault_info *info, const char *block,
649 u32 scratch[4]);
650
651 void adreno_check_and_reenable_stall(struct adreno_gpu *gpu);
652
653 int adreno_read_speedbin(struct device *dev, u32 *speedbin);
654
655 /*
656 * For a5xx and a6xx targets load the zap shader that is used to pull the GPU
657 * out of secure mode
658 */
659 int adreno_zap_shader_load(struct msm_gpu *gpu, u32 pasid);
660
661 /* ringbuffer helpers (the parts that are adreno specific) */
662
663 static inline void
OUT_PKT0(struct msm_ringbuffer * ring,uint16_t regindx,uint16_t cnt)664 OUT_PKT0(struct msm_ringbuffer *ring, uint16_t regindx, uint16_t cnt)
665 {
666 adreno_wait_ring(ring, cnt+1);
667 OUT_RING(ring, CP_TYPE0_PKT | ((cnt-1) << 16) | (regindx & 0x7FFF));
668 }
669
670 /* no-op packet: */
671 static inline void
OUT_PKT2(struct msm_ringbuffer * ring)672 OUT_PKT2(struct msm_ringbuffer *ring)
673 {
674 adreno_wait_ring(ring, 1);
675 OUT_RING(ring, CP_TYPE2_PKT);
676 }
677
678 static inline void
OUT_PKT3(struct msm_ringbuffer * ring,uint8_t opcode,uint16_t cnt)679 OUT_PKT3(struct msm_ringbuffer *ring, uint8_t opcode, uint16_t cnt)
680 {
681 adreno_wait_ring(ring, cnt+1);
682 OUT_RING(ring, CP_TYPE3_PKT | ((cnt-1) << 16) | ((opcode & 0xFF) << 8));
683 }
684
PM4_PARITY(u32 val)685 static inline u32 PM4_PARITY(u32 val)
686 {
687 return (0x9669 >> (0xF & (val ^
688 (val >> 4) ^ (val >> 8) ^ (val >> 12) ^
689 (val >> 16) ^ ((val) >> 20) ^ (val >> 24) ^
690 (val >> 28)))) & 1;
691 }
692
693 /* Maximum number of values that can be executed for one opcode */
694 #define TYPE4_MAX_PAYLOAD 127
695
696 #define PKT4(_reg, _cnt) \
697 (CP_TYPE4_PKT | ((_cnt) << 0) | (PM4_PARITY((_cnt)) << 7) | \
698 (((_reg) & 0x3FFFF) << 8) | (PM4_PARITY((_reg)) << 27))
699
700 static inline void
OUT_PKT4(struct msm_ringbuffer * ring,uint16_t regindx,uint16_t cnt)701 OUT_PKT4(struct msm_ringbuffer *ring, uint16_t regindx, uint16_t cnt)
702 {
703 adreno_wait_ring(ring, cnt + 1);
704 OUT_RING(ring, PKT4(regindx, cnt));
705 }
706
707 #define PKT7(opcode, cnt) \
708 (CP_TYPE7_PKT | (cnt << 0) | (PM4_PARITY(cnt) << 15) | \
709 ((opcode & 0x7F) << 16) | (PM4_PARITY(opcode) << 23))
710
711 static inline void
OUT_PKT7(struct msm_ringbuffer * ring,uint8_t opcode,uint16_t cnt)712 OUT_PKT7(struct msm_ringbuffer *ring, uint8_t opcode, uint16_t cnt)
713 {
714 adreno_wait_ring(ring, cnt + 1);
715 OUT_RING(ring, PKT7(opcode, cnt));
716 }
717
get_wptr(struct msm_ringbuffer * ring)718 static inline uint32_t get_wptr(struct msm_ringbuffer *ring)
719 {
720 return (ring->cur - ring->start) % (MSM_GPU_RINGBUFFER_SZ >> 2);
721 }
722
723 /*
724 * Given a register and a count, return a value to program into
725 * REG_CP_PROTECT_REG(n) - this will block both reads and writes for _len
726 * registers starting at _reg.
727 *
728 * The register base needs to be a multiple of the length. If it is not, the
729 * hardware will quietly mask off the bits for you and shift the size. For
730 * example, if you intend the protection to start at 0x07 for a length of 4
731 * (0x07-0x0A) the hardware will actually protect (0x04-0x07) which might
732 * expose registers you intended to protect!
733 */
734 #define ADRENO_PROTECT_RW(_reg, _len) \
735 ((1 << 30) | (1 << 29) | \
736 ((ilog2((_len)) & 0x1F) << 24) | (((_reg) << 2) & 0xFFFFF))
737
738 /*
739 * Same as above, but allow reads over the range. For areas of mixed use (such
740 * as performance counters) this allows us to protect a much larger range with a
741 * single register
742 */
743 #define ADRENO_PROTECT_RDONLY(_reg, _len) \
744 ((1 << 29) \
745 ((ilog2((_len)) & 0x1F) << 24) | (((_reg) << 2) & 0xFFFFF))
746
747
748 #define gpu_poll_timeout(gpu, addr, val, cond, interval, timeout) \
749 readl_poll_timeout((gpu)->mmio + ((addr) << 2), val, cond, \
750 interval, timeout)
751
752 #endif /* __ADRENO_GPU_H__ */
753