adreno_gpu.h 19 KB

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