msm_gpu.h 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (C) 2013 Red Hat
  4. * Author: Rob Clark <[email protected]>
  5. */
  6. #ifndef __MSM_GPU_H__
  7. #define __MSM_GPU_H__
  8. #include <linux/adreno-smmu-priv.h>
  9. #include <linux/clk.h>
  10. #include <linux/devfreq.h>
  11. #include <linux/interconnect.h>
  12. #include <linux/pm_opp.h>
  13. #include <linux/regulator/consumer.h>
  14. #include <linux/reset.h>
  15. #include "msm_drv.h"
  16. #include "msm_fence.h"
  17. #include "msm_ringbuffer.h"
  18. #include "msm_gem.h"
  19. struct msm_gem_submit;
  20. struct msm_gpu_perfcntr;
  21. struct msm_gpu_state;
  22. struct msm_file_private;
  23. struct msm_gpu_config {
  24. const char *ioname;
  25. unsigned int nr_rings;
  26. };
  27. /* So far, with hardware that I've seen to date, we can have:
  28. * + zero, one, or two z180 2d cores
  29. * + a3xx or a2xx 3d core, which share a common CP (the firmware
  30. * for the CP seems to implement some different PM4 packet types
  31. * but the basics of cmdstream submission are the same)
  32. *
  33. * Which means that the eventual complete "class" hierarchy, once
  34. * support for all past and present hw is in place, becomes:
  35. * + msm_gpu
  36. * + adreno_gpu
  37. * + a3xx_gpu
  38. * + a2xx_gpu
  39. * + z180_gpu
  40. */
  41. struct msm_gpu_funcs {
  42. int (*get_param)(struct msm_gpu *gpu, struct msm_file_private *ctx,
  43. uint32_t param, uint64_t *value, uint32_t *len);
  44. int (*set_param)(struct msm_gpu *gpu, struct msm_file_private *ctx,
  45. uint32_t param, uint64_t value, uint32_t len);
  46. int (*hw_init)(struct msm_gpu *gpu);
  47. int (*pm_suspend)(struct msm_gpu *gpu);
  48. int (*pm_resume)(struct msm_gpu *gpu);
  49. void (*submit)(struct msm_gpu *gpu, struct msm_gem_submit *submit);
  50. void (*flush)(struct msm_gpu *gpu, struct msm_ringbuffer *ring);
  51. irqreturn_t (*irq)(struct msm_gpu *irq);
  52. struct msm_ringbuffer *(*active_ring)(struct msm_gpu *gpu);
  53. void (*recover)(struct msm_gpu *gpu);
  54. void (*destroy)(struct msm_gpu *gpu);
  55. #if defined(CONFIG_DEBUG_FS) || defined(CONFIG_DEV_COREDUMP)
  56. /* show GPU status in debugfs: */
  57. void (*show)(struct msm_gpu *gpu, struct msm_gpu_state *state,
  58. struct drm_printer *p);
  59. /* for generation specific debugfs: */
  60. void (*debugfs_init)(struct msm_gpu *gpu, struct drm_minor *minor);
  61. #endif
  62. /* note: gpu_busy() can assume that we have been pm_resumed */
  63. u64 (*gpu_busy)(struct msm_gpu *gpu, unsigned long *out_sample_rate);
  64. struct msm_gpu_state *(*gpu_state_get)(struct msm_gpu *gpu);
  65. int (*gpu_state_put)(struct msm_gpu_state *state);
  66. unsigned long (*gpu_get_freq)(struct msm_gpu *gpu);
  67. /* note: gpu_set_freq() can assume that we have been pm_resumed */
  68. void (*gpu_set_freq)(struct msm_gpu *gpu, struct dev_pm_opp *opp,
  69. bool suspended);
  70. struct msm_gem_address_space *(*create_address_space)
  71. (struct msm_gpu *gpu, struct platform_device *pdev);
  72. struct msm_gem_address_space *(*create_private_address_space)
  73. (struct msm_gpu *gpu);
  74. uint32_t (*get_rptr)(struct msm_gpu *gpu, struct msm_ringbuffer *ring);
  75. /**
  76. * progress: Has the GPU made progress?
  77. *
  78. * Return true if GPU position in cmdstream has advanced (or changed)
  79. * since the last call. To avoid false negatives, this should account
  80. * for cmdstream that is buffered in this FIFO upstream of the CP fw.
  81. */
  82. bool (*progress)(struct msm_gpu *gpu, struct msm_ringbuffer *ring);
  83. };
  84. /* Additional state for iommu faults: */
  85. struct msm_gpu_fault_info {
  86. u64 ttbr0;
  87. unsigned long iova;
  88. int flags;
  89. const char *type;
  90. const char *block;
  91. };
  92. /**
  93. * struct msm_gpu_devfreq - devfreq related state
  94. */
  95. struct msm_gpu_devfreq {
  96. /** devfreq: devfreq instance */
  97. struct devfreq *devfreq;
  98. /** lock: lock for "suspended", "busy_cycles", and "time" */
  99. struct mutex lock;
  100. /**
  101. * idle_constraint:
  102. *
  103. * A PM QoS constraint to limit max freq while the GPU is idle.
  104. */
  105. struct dev_pm_qos_request idle_freq;
  106. /**
  107. * boost_constraint:
  108. *
  109. * A PM QoS constraint to boost min freq for a period of time
  110. * until the boost expires.
  111. */
  112. struct dev_pm_qos_request boost_freq;
  113. /**
  114. * busy_cycles: Last busy counter value, for calculating elapsed busy
  115. * cycles since last sampling period.
  116. */
  117. u64 busy_cycles;
  118. /** time: Time of last sampling period. */
  119. ktime_t time;
  120. /** idle_time: Time of last transition to idle: */
  121. ktime_t idle_time;
  122. struct devfreq_dev_status average_status;
  123. /**
  124. * idle_work:
  125. *
  126. * Used to delay clamping to idle freq on active->idle transition.
  127. */
  128. struct msm_hrtimer_work idle_work;
  129. /**
  130. * boost_work:
  131. *
  132. * Used to reset the boost_constraint after the boost period has
  133. * elapsed
  134. */
  135. struct msm_hrtimer_work boost_work;
  136. /** suspended: tracks if we're suspended */
  137. bool suspended;
  138. };
  139. struct msm_gpu {
  140. const char *name;
  141. struct drm_device *dev;
  142. struct platform_device *pdev;
  143. const struct msm_gpu_funcs *funcs;
  144. struct adreno_smmu_priv adreno_smmu;
  145. /* performance counters (hw & sw): */
  146. spinlock_t perf_lock;
  147. bool perfcntr_active;
  148. struct {
  149. bool active;
  150. ktime_t time;
  151. } last_sample;
  152. uint32_t totaltime, activetime; /* sw counters */
  153. uint32_t last_cntrs[5]; /* hw counters */
  154. const struct msm_gpu_perfcntr *perfcntrs;
  155. uint32_t num_perfcntrs;
  156. struct msm_ringbuffer *rb[MSM_GPU_MAX_RINGS];
  157. int nr_rings;
  158. /**
  159. * sysprof_active:
  160. *
  161. * The count of contexts that have enabled system profiling.
  162. */
  163. refcount_t sysprof_active;
  164. /**
  165. * cur_ctx_seqno:
  166. *
  167. * The ctx->seqno value of the last context to submit rendering,
  168. * and the one with current pgtables installed (for generations
  169. * that support per-context pgtables). Tracked by seqno rather
  170. * than pointer value to avoid dangling pointers, and cases where
  171. * a ctx can be freed and a new one created with the same address.
  172. */
  173. int cur_ctx_seqno;
  174. /**
  175. * lock:
  176. *
  177. * General lock for serializing all the gpu things.
  178. *
  179. * TODO move to per-ring locking where feasible (ie. submit/retire
  180. * path, etc)
  181. */
  182. struct mutex lock;
  183. /**
  184. * active_submits:
  185. *
  186. * The number of submitted but not yet retired submits, used to
  187. * determine transitions between active and idle.
  188. *
  189. * Protected by active_lock
  190. */
  191. int active_submits;
  192. /** lock: protects active_submits and idle/active transitions */
  193. struct mutex active_lock;
  194. /* does gpu need hw_init? */
  195. bool needs_hw_init;
  196. /**
  197. * global_faults: number of GPU hangs not attributed to a particular
  198. * address space
  199. */
  200. int global_faults;
  201. void __iomem *mmio;
  202. int irq;
  203. struct msm_gem_address_space *aspace;
  204. /* Power Control: */
  205. struct regulator *gpu_reg, *gpu_cx;
  206. struct clk_bulk_data *grp_clks;
  207. int nr_clocks;
  208. struct clk *ebi1_clk, *core_clk, *rbbmtimer_clk;
  209. uint32_t fast_rate;
  210. /* Hang and Inactivity Detection:
  211. */
  212. #define DRM_MSM_INACTIVE_PERIOD 66 /* in ms (roughly four frames) */
  213. #define DRM_MSM_HANGCHECK_DEFAULT_PERIOD 500 /* in ms */
  214. #define DRM_MSM_HANGCHECK_PROGRESS_RETRIES 3
  215. struct timer_list hangcheck_timer;
  216. /* Fault info for most recent iova fault: */
  217. struct msm_gpu_fault_info fault_info;
  218. /* work for handling GPU ioval faults: */
  219. struct kthread_work fault_work;
  220. /* work for handling GPU recovery: */
  221. struct kthread_work recover_work;
  222. /** retire_event: notified when submits are retired: */
  223. wait_queue_head_t retire_event;
  224. /* work for handling active-list retiring: */
  225. struct kthread_work retire_work;
  226. /* worker for retire/recover: */
  227. struct kthread_worker *worker;
  228. struct drm_gem_object *memptrs_bo;
  229. struct msm_gpu_devfreq devfreq;
  230. uint32_t suspend_count;
  231. struct msm_gpu_state *crashstate;
  232. /* Enable clamping to idle freq when inactive: */
  233. bool clamp_to_idle;
  234. /* True if the hardware supports expanded apriv (a650 and newer) */
  235. bool hw_apriv;
  236. struct thermal_cooling_device *cooling;
  237. /* To poll for cx gdsc collapse during gpu recovery */
  238. struct reset_control *cx_collapse;
  239. };
  240. static inline struct msm_gpu *dev_to_gpu(struct device *dev)
  241. {
  242. struct adreno_smmu_priv *adreno_smmu = dev_get_drvdata(dev);
  243. if (!adreno_smmu)
  244. return NULL;
  245. return container_of(adreno_smmu, struct msm_gpu, adreno_smmu);
  246. }
  247. /* It turns out that all targets use the same ringbuffer size */
  248. #define MSM_GPU_RINGBUFFER_SZ SZ_32K
  249. #define MSM_GPU_RINGBUFFER_BLKSIZE 32
  250. #define MSM_GPU_RB_CNTL_DEFAULT \
  251. (AXXX_CP_RB_CNTL_BUFSZ(ilog2(MSM_GPU_RINGBUFFER_SZ / 8)) | \
  252. AXXX_CP_RB_CNTL_BLKSZ(ilog2(MSM_GPU_RINGBUFFER_BLKSIZE / 8)))
  253. static inline bool msm_gpu_active(struct msm_gpu *gpu)
  254. {
  255. int i;
  256. for (i = 0; i < gpu->nr_rings; i++) {
  257. struct msm_ringbuffer *ring = gpu->rb[i];
  258. if (fence_after(ring->fctx->last_fence, ring->memptrs->fence))
  259. return true;
  260. }
  261. return false;
  262. }
  263. /* Perf-Counters:
  264. * The select_reg and select_val are just there for the benefit of the child
  265. * class that actually enables the perf counter.. but msm_gpu base class
  266. * will handle sampling/displaying the counters.
  267. */
  268. struct msm_gpu_perfcntr {
  269. uint32_t select_reg;
  270. uint32_t sample_reg;
  271. uint32_t select_val;
  272. const char *name;
  273. };
  274. /*
  275. * The number of priority levels provided by drm gpu scheduler. The
  276. * DRM_SCHED_PRIORITY_KERNEL priority level is treated specially in some
  277. * cases, so we don't use it (no need for kernel generated jobs).
  278. */
  279. #define NR_SCHED_PRIORITIES (1 + DRM_SCHED_PRIORITY_HIGH - DRM_SCHED_PRIORITY_MIN)
  280. /**
  281. * struct msm_file_private - per-drm_file context
  282. *
  283. * @queuelock: synchronizes access to submitqueues list
  284. * @submitqueues: list of &msm_gpu_submitqueue created by userspace
  285. * @queueid: counter incremented each time a submitqueue is created,
  286. * used to assign &msm_gpu_submitqueue.id
  287. * @aspace: the per-process GPU address-space
  288. * @ref: reference count
  289. * @seqno: unique per process seqno
  290. */
  291. struct msm_file_private {
  292. rwlock_t queuelock;
  293. struct list_head submitqueues;
  294. int queueid;
  295. struct msm_gem_address_space *aspace;
  296. struct kref ref;
  297. int seqno;
  298. /**
  299. * sysprof:
  300. *
  301. * The value of MSM_PARAM_SYSPROF set by userspace. This is
  302. * intended to be used by system profiling tools like Mesa's
  303. * pps-producer (perfetto), and restricted to CAP_SYS_ADMIN.
  304. *
  305. * Setting a value of 1 will preserve performance counters across
  306. * context switches. Setting a value of 2 will in addition
  307. * suppress suspend. (Performance counters lose state across
  308. * power collapse, which is undesirable for profiling in some
  309. * cases.)
  310. *
  311. * The value automatically reverts to zero when the drm device
  312. * file is closed.
  313. */
  314. int sysprof;
  315. /**
  316. * comm: Overridden task comm, see MSM_PARAM_COMM
  317. *
  318. * Accessed under msm_gpu::lock
  319. */
  320. char *comm;
  321. /**
  322. * cmdline: Overridden task cmdline, see MSM_PARAM_CMDLINE
  323. *
  324. * Accessed under msm_gpu::lock
  325. */
  326. char *cmdline;
  327. /**
  328. * elapsed:
  329. *
  330. * The total (cumulative) elapsed time GPU was busy with rendering
  331. * from this context in ns.
  332. */
  333. uint64_t elapsed_ns;
  334. /**
  335. * cycles:
  336. *
  337. * The total (cumulative) GPU cycles elapsed attributed to this
  338. * context.
  339. */
  340. uint64_t cycles;
  341. /**
  342. * entities:
  343. *
  344. * Table of per-priority-level sched entities used by submitqueues
  345. * associated with this &drm_file. Because some userspace apps
  346. * make assumptions about rendering from multiple gl contexts
  347. * (of the same priority) within the process happening in FIFO
  348. * order without requiring any fencing beyond MakeCurrent(), we
  349. * create at most one &drm_sched_entity per-process per-priority-
  350. * level.
  351. */
  352. struct drm_sched_entity *entities[NR_SCHED_PRIORITIES * MSM_GPU_MAX_RINGS];
  353. };
  354. /**
  355. * msm_gpu_convert_priority - Map userspace priority to ring # and sched priority
  356. *
  357. * @gpu: the gpu instance
  358. * @prio: the userspace priority level
  359. * @ring_nr: [out] the ringbuffer the userspace priority maps to
  360. * @sched_prio: [out] the gpu scheduler priority level which the userspace
  361. * priority maps to
  362. *
  363. * With drm/scheduler providing it's own level of prioritization, our total
  364. * number of available priority levels is (nr_rings * NR_SCHED_PRIORITIES).
  365. * Each ring is associated with it's own scheduler instance. However, our
  366. * UABI is that lower numerical values are higher priority. So mapping the
  367. * single userspace priority level into ring_nr and sched_prio takes some
  368. * care. The userspace provided priority (when a submitqueue is created)
  369. * is mapped to ring nr and scheduler priority as such:
  370. *
  371. * ring_nr = userspace_prio / NR_SCHED_PRIORITIES
  372. * sched_prio = NR_SCHED_PRIORITIES -
  373. * (userspace_prio % NR_SCHED_PRIORITIES) - 1
  374. *
  375. * This allows generations without preemption (nr_rings==1) to have some
  376. * amount of prioritization, and provides more priority levels for gens
  377. * that do have preemption.
  378. */
  379. static inline int msm_gpu_convert_priority(struct msm_gpu *gpu, int prio,
  380. unsigned *ring_nr, enum drm_sched_priority *sched_prio)
  381. {
  382. unsigned rn, sp;
  383. rn = div_u64_rem(prio, NR_SCHED_PRIORITIES, &sp);
  384. /* invert sched priority to map to higher-numeric-is-higher-
  385. * priority convention
  386. */
  387. sp = NR_SCHED_PRIORITIES - sp - 1;
  388. if (rn >= gpu->nr_rings)
  389. return -EINVAL;
  390. *ring_nr = rn;
  391. *sched_prio = sp;
  392. return 0;
  393. }
  394. /**
  395. * struct msm_gpu_submitqueues - Userspace created context.
  396. *
  397. * A submitqueue is associated with a gl context or vk queue (or equiv)
  398. * in userspace.
  399. *
  400. * @id: userspace id for the submitqueue, unique within the drm_file
  401. * @flags: userspace flags for the submitqueue, specified at creation
  402. * (currently unusued)
  403. * @ring_nr: the ringbuffer used by this submitqueue, which is determined
  404. * by the submitqueue's priority
  405. * @faults: the number of GPU hangs associated with this submitqueue
  406. * @last_fence: the sequence number of the last allocated fence (for error
  407. * checking)
  408. * @ctx: the per-drm_file context associated with the submitqueue (ie.
  409. * which set of pgtables do submits jobs associated with the
  410. * submitqueue use)
  411. * @node: node in the context's list of submitqueues
  412. * @fence_idr: maps fence-id to dma_fence for userspace visible fence
  413. * seqno, protected by submitqueue lock
  414. * @idr_lock: for serializing access to fence_idr
  415. * @lock: submitqueue lock for serializing submits on a queue
  416. * @ref: reference count
  417. * @entity: the submit job-queue
  418. */
  419. struct msm_gpu_submitqueue {
  420. int id;
  421. u32 flags;
  422. u32 ring_nr;
  423. int faults;
  424. uint32_t last_fence;
  425. struct msm_file_private *ctx;
  426. struct list_head node;
  427. struct idr fence_idr;
  428. struct spinlock idr_lock;
  429. struct mutex lock;
  430. struct kref ref;
  431. struct drm_sched_entity *entity;
  432. };
  433. struct msm_gpu_state_bo {
  434. u64 iova;
  435. size_t size;
  436. void *data;
  437. bool encoded;
  438. char name[32];
  439. };
  440. struct msm_gpu_state {
  441. struct kref ref;
  442. struct timespec64 time;
  443. struct {
  444. u64 iova;
  445. u32 fence;
  446. u32 seqno;
  447. u32 rptr;
  448. u32 wptr;
  449. void *data;
  450. int data_size;
  451. bool encoded;
  452. } ring[MSM_GPU_MAX_RINGS];
  453. int nr_registers;
  454. u32 *registers;
  455. u32 rbbm_status;
  456. char *comm;
  457. char *cmd;
  458. struct msm_gpu_fault_info fault_info;
  459. int nr_bos;
  460. struct msm_gpu_state_bo *bos;
  461. };
  462. static inline void gpu_write(struct msm_gpu *gpu, u32 reg, u32 data)
  463. {
  464. msm_writel(data, gpu->mmio + (reg << 2));
  465. }
  466. static inline u32 gpu_read(struct msm_gpu *gpu, u32 reg)
  467. {
  468. return msm_readl(gpu->mmio + (reg << 2));
  469. }
  470. static inline void gpu_rmw(struct msm_gpu *gpu, u32 reg, u32 mask, u32 or)
  471. {
  472. msm_rmw(gpu->mmio + (reg << 2), mask, or);
  473. }
  474. static inline u64 gpu_read64(struct msm_gpu *gpu, u32 reg)
  475. {
  476. u64 val;
  477. /*
  478. * Why not a readq here? Two reasons: 1) many of the LO registers are
  479. * not quad word aligned and 2) the GPU hardware designers have a bit
  480. * of a history of putting registers where they fit, especially in
  481. * spins. The longer a GPU family goes the higher the chance that
  482. * we'll get burned. We could do a series of validity checks if we
  483. * wanted to, but really is a readq() that much better? Nah.
  484. */
  485. /*
  486. * For some lo/hi registers (like perfcounters), the hi value is latched
  487. * when the lo is read, so make sure to read the lo first to trigger
  488. * that
  489. */
  490. val = (u64) msm_readl(gpu->mmio + (reg << 2));
  491. val |= ((u64) msm_readl(gpu->mmio + ((reg + 1) << 2)) << 32);
  492. return val;
  493. }
  494. static inline void gpu_write64(struct msm_gpu *gpu, u32 reg, u64 val)
  495. {
  496. /* Why not a writeq here? Read the screed above */
  497. msm_writel(lower_32_bits(val), gpu->mmio + (reg << 2));
  498. msm_writel(upper_32_bits(val), gpu->mmio + ((reg + 1) << 2));
  499. }
  500. int msm_gpu_pm_suspend(struct msm_gpu *gpu);
  501. int msm_gpu_pm_resume(struct msm_gpu *gpu);
  502. void msm_gpu_show_fdinfo(struct msm_gpu *gpu, struct msm_file_private *ctx,
  503. struct drm_printer *p);
  504. int msm_submitqueue_init(struct drm_device *drm, struct msm_file_private *ctx);
  505. struct msm_gpu_submitqueue *msm_submitqueue_get(struct msm_file_private *ctx,
  506. u32 id);
  507. int msm_submitqueue_create(struct drm_device *drm,
  508. struct msm_file_private *ctx,
  509. u32 prio, u32 flags, u32 *id);
  510. int msm_submitqueue_query(struct drm_device *drm, struct msm_file_private *ctx,
  511. struct drm_msm_submitqueue_query *args);
  512. int msm_submitqueue_remove(struct msm_file_private *ctx, u32 id);
  513. void msm_submitqueue_close(struct msm_file_private *ctx);
  514. void msm_submitqueue_destroy(struct kref *kref);
  515. int msm_file_private_set_sysprof(struct msm_file_private *ctx,
  516. struct msm_gpu *gpu, int sysprof);
  517. void __msm_file_private_destroy(struct kref *kref);
  518. static inline void msm_file_private_put(struct msm_file_private *ctx)
  519. {
  520. kref_put(&ctx->ref, __msm_file_private_destroy);
  521. }
  522. static inline struct msm_file_private *msm_file_private_get(
  523. struct msm_file_private *ctx)
  524. {
  525. kref_get(&ctx->ref);
  526. return ctx;
  527. }
  528. void msm_devfreq_init(struct msm_gpu *gpu);
  529. void msm_devfreq_cleanup(struct msm_gpu *gpu);
  530. void msm_devfreq_resume(struct msm_gpu *gpu);
  531. void msm_devfreq_suspend(struct msm_gpu *gpu);
  532. void msm_devfreq_boost(struct msm_gpu *gpu, unsigned factor);
  533. void msm_devfreq_active(struct msm_gpu *gpu);
  534. void msm_devfreq_idle(struct msm_gpu *gpu);
  535. int msm_gpu_hw_init(struct msm_gpu *gpu);
  536. void msm_gpu_perfcntr_start(struct msm_gpu *gpu);
  537. void msm_gpu_perfcntr_stop(struct msm_gpu *gpu);
  538. int msm_gpu_perfcntr_sample(struct msm_gpu *gpu, uint32_t *activetime,
  539. uint32_t *totaltime, uint32_t ncntrs, uint32_t *cntrs);
  540. void msm_gpu_retire(struct msm_gpu *gpu);
  541. void msm_gpu_submit(struct msm_gpu *gpu, struct msm_gem_submit *submit);
  542. int msm_gpu_init(struct drm_device *drm, struct platform_device *pdev,
  543. struct msm_gpu *gpu, const struct msm_gpu_funcs *funcs,
  544. const char *name, struct msm_gpu_config *config);
  545. struct msm_gem_address_space *
  546. msm_gpu_create_private_address_space(struct msm_gpu *gpu, struct task_struct *task);
  547. void msm_gpu_cleanup(struct msm_gpu *gpu);
  548. struct msm_gpu *adreno_load_gpu(struct drm_device *dev);
  549. void __init adreno_register(void);
  550. void __exit adreno_unregister(void);
  551. static inline void msm_submitqueue_put(struct msm_gpu_submitqueue *queue)
  552. {
  553. if (queue)
  554. kref_put(&queue->ref, msm_submitqueue_destroy);
  555. }
  556. static inline struct msm_gpu_state *msm_gpu_crashstate_get(struct msm_gpu *gpu)
  557. {
  558. struct msm_gpu_state *state = NULL;
  559. mutex_lock(&gpu->lock);
  560. if (gpu->crashstate) {
  561. kref_get(&gpu->crashstate->ref);
  562. state = gpu->crashstate;
  563. }
  564. mutex_unlock(&gpu->lock);
  565. return state;
  566. }
  567. static inline void msm_gpu_crashstate_put(struct msm_gpu *gpu)
  568. {
  569. mutex_lock(&gpu->lock);
  570. if (gpu->crashstate) {
  571. if (gpu->funcs->gpu_state_put(gpu->crashstate))
  572. gpu->crashstate = NULL;
  573. }
  574. mutex_unlock(&gpu->lock);
  575. }
  576. /*
  577. * Simple macro to semi-cleanly add the MAP_PRIV flag for targets that can
  578. * support expanded privileges
  579. */
  580. #define check_apriv(gpu, flags) \
  581. (((gpu)->hw_apriv ? MSM_BO_MAP_PRIV : 0) | (flags))
  582. #endif /* __MSM_GPU_H__ */