adreno_gpu.h 20 KB

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