msm_gpu.h 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (C) 2013 Red Hat
  4. * Author: Rob Clark <robdclark@gmail.com>
  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 "msm_drv.h"
  15. #include "msm_fence.h"
  16. #include "msm_gpu_trace.h"
  17. #include "msm_ringbuffer.h"
  18. #include "msm_gem.h"
  19. struct msm_gem_submit;
  20. struct msm_gem_vm_log_entry;
  21. struct msm_gpu_perfcntr;
  22. struct msm_gpu_state;
  23. struct msm_context;
  24. struct msm_gpu_config {
  25. const char *ioname;
  26. unsigned int nr_rings;
  27. };
  28. /* So far, with hardware that I've seen to date, we can have:
  29. * + zero, one, or two z180 2d cores
  30. * + a3xx or a2xx 3d core, which share a common CP (the firmware
  31. * for the CP seems to implement some different PM4 packet types
  32. * but the basics of cmdstream submission are the same)
  33. *
  34. * Which means that the eventual complete "class" hierarchy, once
  35. * support for all past and present hw is in place, becomes:
  36. * + msm_gpu
  37. * + adreno_gpu
  38. * + a3xx_gpu
  39. * + a2xx_gpu
  40. * + z180_gpu
  41. */
  42. struct msm_gpu_funcs {
  43. int (*get_param)(struct msm_gpu *gpu, struct msm_context *ctx,
  44. uint32_t param, uint64_t *value, uint32_t *len);
  45. int (*set_param)(struct msm_gpu *gpu, struct msm_context *ctx,
  46. uint32_t param, uint64_t value, uint32_t len);
  47. int (*hw_init)(struct msm_gpu *gpu);
  48. /**
  49. * @ucode_load: Optional hook to upload fw to GEM objs
  50. */
  51. int (*ucode_load)(struct msm_gpu *gpu);
  52. int (*pm_suspend)(struct msm_gpu *gpu);
  53. int (*pm_resume)(struct msm_gpu *gpu);
  54. void (*submit)(struct msm_gpu *gpu, struct msm_gem_submit *submit);
  55. void (*flush)(struct msm_gpu *gpu, struct msm_ringbuffer *ring);
  56. irqreturn_t (*irq)(struct msm_gpu *irq);
  57. struct msm_ringbuffer *(*active_ring)(struct msm_gpu *gpu);
  58. void (*recover)(struct msm_gpu *gpu);
  59. void (*destroy)(struct msm_gpu *gpu);
  60. #if defined(CONFIG_DEBUG_FS) || defined(CONFIG_DEV_COREDUMP)
  61. /* show GPU status in debugfs: */
  62. void (*show)(struct msm_gpu *gpu, struct msm_gpu_state *state,
  63. struct drm_printer *p);
  64. /* for generation specific debugfs: */
  65. void (*debugfs_init)(struct msm_gpu *gpu, struct drm_minor *minor);
  66. #endif
  67. /* note: gpu_busy() can assume that we have been pm_resumed */
  68. u64 (*gpu_busy)(struct msm_gpu *gpu, unsigned long *out_sample_rate);
  69. struct msm_gpu_state *(*gpu_state_get)(struct msm_gpu *gpu);
  70. int (*gpu_state_put)(struct msm_gpu_state *state);
  71. unsigned long (*gpu_get_freq)(struct msm_gpu *gpu);
  72. /* note: gpu_set_freq() can assume that we have been pm_resumed */
  73. void (*gpu_set_freq)(struct msm_gpu *gpu, struct dev_pm_opp *opp,
  74. bool suspended);
  75. struct drm_gpuvm *(*create_vm)(struct msm_gpu *gpu, struct platform_device *pdev);
  76. struct drm_gpuvm *(*create_private_vm)(struct msm_gpu *gpu, bool kernel_managed);
  77. uint32_t (*get_rptr)(struct msm_gpu *gpu, struct msm_ringbuffer *ring);
  78. /**
  79. * progress: Has the GPU made progress?
  80. *
  81. * Return true if GPU position in cmdstream has advanced (or changed)
  82. * since the last call. To avoid false negatives, this should account
  83. * for cmdstream that is buffered in this FIFO upstream of the CP fw.
  84. */
  85. bool (*progress)(struct msm_gpu *gpu, struct msm_ringbuffer *ring);
  86. void (*sysprof_setup)(struct msm_gpu *gpu);
  87. };
  88. /* Additional state for iommu faults: */
  89. struct msm_gpu_fault_info {
  90. u64 ttbr0;
  91. unsigned long iova;
  92. int flags;
  93. const char *type;
  94. const char *block;
  95. /* Information about what we think/expect is the current SMMU state,
  96. * for example expected_ttbr0 should match smmu_info.ttbr0 which
  97. * was read back from SMMU registers.
  98. */
  99. phys_addr_t pgtbl_ttbr0;
  100. u64 ptes[4];
  101. int asid;
  102. };
  103. /**
  104. * struct msm_gpu_devfreq - devfreq related state
  105. */
  106. struct msm_gpu_devfreq {
  107. /** @devfreq: devfreq instance */
  108. struct devfreq *devfreq;
  109. /** @lock: lock for "suspended", "busy_cycles", and "time" */
  110. struct mutex lock;
  111. /**
  112. * @idle_freq:
  113. * Shadow frequency used while the GPU is idle. From the PoV of
  114. * the devfreq governor, we are continuing to sample busyness and
  115. * adjust frequency while the GPU is idle, but we use this shadow
  116. * value as the GPU is actually clamped to minimum frequency while
  117. * it is inactive.
  118. */
  119. unsigned long idle_freq;
  120. /**
  121. * @boost_freq:
  122. * A PM QoS constraint to boost min freq for a period of time
  123. * until the boost expires.
  124. */
  125. struct dev_pm_qos_request boost_freq;
  126. /**
  127. * @busy_cycles: Last busy counter value, for calculating elapsed busy
  128. * cycles since last sampling period.
  129. */
  130. u64 busy_cycles;
  131. /** @time: Time of last sampling period. */
  132. ktime_t time;
  133. /** @idle_time: Time of last transition to idle. */
  134. ktime_t idle_time;
  135. /**
  136. * @idle_work:
  137. * Used to delay clamping to idle freq on active->idle transition.
  138. */
  139. struct msm_hrtimer_work idle_work;
  140. /**
  141. * @boost_work:
  142. * Used to reset the boost_constraint after the boost period has
  143. * elapsed
  144. */
  145. struct msm_hrtimer_work boost_work;
  146. /** @suspended: tracks if we're suspended */
  147. bool suspended;
  148. };
  149. struct msm_gpu {
  150. const char *name;
  151. struct drm_device *dev;
  152. struct platform_device *pdev;
  153. const struct msm_gpu_funcs *funcs;
  154. struct adreno_smmu_priv adreno_smmu;
  155. /* performance counters (hw & sw): */
  156. spinlock_t perf_lock;
  157. bool perfcntr_active;
  158. struct {
  159. bool active;
  160. ktime_t time;
  161. } last_sample;
  162. uint32_t totaltime, activetime; /* sw counters */
  163. uint32_t last_cntrs[5]; /* hw counters */
  164. const struct msm_gpu_perfcntr *perfcntrs;
  165. uint32_t num_perfcntrs;
  166. struct msm_ringbuffer *rb[MSM_GPU_MAX_RINGS];
  167. int nr_rings;
  168. /**
  169. * sysprof_active:
  170. *
  171. * The count of contexts that have enabled system profiling.
  172. */
  173. refcount_t sysprof_active;
  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 drm_gpuvm *vm;
  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. /* work for handling GPU recovery: */
  217. struct kthread_work recover_work;
  218. /** retire_event: notified when submits are retired: */
  219. wait_queue_head_t retire_event;
  220. /* work for handling active-list retiring: */
  221. struct kthread_work retire_work;
  222. /* worker for retire/recover: */
  223. struct kthread_worker *worker;
  224. struct drm_gem_object *memptrs_bo;
  225. struct msm_gpu_devfreq devfreq;
  226. uint32_t suspend_count;
  227. struct msm_gpu_state *crashstate;
  228. /* True if the hardware supports expanded apriv (a650 and newer) */
  229. bool hw_apriv;
  230. /**
  231. * @allow_relocs: allow relocs in SUBMIT ioctl
  232. *
  233. * Mesa won't use relocs for driver version 1.4.0 and later. This
  234. * switch-over happened early enough in mesa a6xx bringup that we
  235. * can disallow relocs for a6xx and newer.
  236. */
  237. bool allow_relocs;
  238. struct thermal_cooling_device *cooling;
  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. static inline bool
  248. adreno_smmu_has_prr(struct msm_gpu *gpu)
  249. {
  250. struct adreno_smmu_priv *adreno_smmu = dev_get_drvdata(&gpu->pdev->dev);
  251. if (!adreno_smmu)
  252. return false;
  253. return adreno_smmu && adreno_smmu->set_prr_addr;
  254. }
  255. /* It turns out that all targets use the same ringbuffer size */
  256. #define MSM_GPU_RINGBUFFER_SZ SZ_32K
  257. #define MSM_GPU_RINGBUFFER_BLKSIZE 32
  258. #define MSM_GPU_RB_CNTL_DEFAULT \
  259. (AXXX_CP_RB_CNTL_BUFSZ(ilog2(MSM_GPU_RINGBUFFER_SZ / 8)) | \
  260. AXXX_CP_RB_CNTL_BLKSZ(ilog2(MSM_GPU_RINGBUFFER_BLKSIZE / 8)))
  261. static inline bool msm_gpu_active(struct msm_gpu *gpu)
  262. {
  263. int i;
  264. for (i = 0; i < gpu->nr_rings; i++) {
  265. struct msm_ringbuffer *ring = gpu->rb[i];
  266. if (fence_after(ring->fctx->last_fence, ring->memptrs->fence))
  267. return true;
  268. }
  269. return false;
  270. }
  271. /* Perf-Counters:
  272. * The select_reg and select_val are just there for the benefit of the child
  273. * class that actually enables the perf counter.. but msm_gpu base class
  274. * will handle sampling/displaying the counters.
  275. */
  276. struct msm_gpu_perfcntr {
  277. uint32_t select_reg;
  278. uint32_t sample_reg;
  279. uint32_t select_val;
  280. const char *name;
  281. };
  282. /*
  283. * The number of priority levels provided by drm gpu scheduler. The
  284. * DRM_SCHED_PRIORITY_KERNEL priority level is treated specially in some
  285. * cases, so we don't use it (no need for kernel generated jobs).
  286. */
  287. #define NR_SCHED_PRIORITIES (1 + DRM_SCHED_PRIORITY_LOW - DRM_SCHED_PRIORITY_HIGH)
  288. /**
  289. * struct msm_context - per-drm_file context
  290. */
  291. struct msm_context {
  292. /** @queuelock: synchronizes access to submitqueues list */
  293. rwlock_t queuelock;
  294. /** @submitqueues: list of &msm_gpu_submitqueue created by userspace */
  295. struct list_head submitqueues;
  296. /**
  297. * @queueid:
  298. * Counter incremented each time a submitqueue is created, used to
  299. * assign &msm_gpu_submitqueue.id
  300. */
  301. int queueid;
  302. /**
  303. * @closed: The device file associated with this context has been closed.
  304. * Once the device is closed, any submits that have not been written
  305. * to the ring buffer are no-op'd.
  306. */
  307. bool closed;
  308. /**
  309. * @userspace_managed_vm:
  310. * Has userspace opted-in to userspace managed VM (ie. VM_BIND) via
  311. * MSM_PARAM_EN_VM_BIND?
  312. */
  313. bool userspace_managed_vm;
  314. /**
  315. * @vm:
  316. * The per-process GPU address-space. Do not access directly, use
  317. * msm_context_vm().
  318. */
  319. struct drm_gpuvm *vm;
  320. /** @ref: the reference count */
  321. struct kref ref;
  322. /**
  323. * @seqno:
  324. * A unique per-process sequence number. Used to detect context
  325. * switches, without relying on keeping a, potentially dangling,
  326. * pointer to the previous context.
  327. */
  328. int seqno;
  329. /**
  330. * @sysprof:
  331. * The value of MSM_PARAM_SYSPROF set by userspace. This is
  332. * intended to be used by system profiling tools like Mesa's
  333. * pps-producer (perfetto), and restricted to CAP_SYS_ADMIN.
  334. *
  335. * Setting a value of 1 will preserve performance counters across
  336. * context switches. Setting a value of 2 will in addition
  337. * suppress suspend. (Performance counters lose state across
  338. * power collapse, which is undesirable for profiling in some
  339. * cases.)
  340. *
  341. * The value automatically reverts to zero when the drm device
  342. * file is closed.
  343. */
  344. int sysprof;
  345. /**
  346. * @comm: Overridden task comm, see MSM_PARAM_COMM
  347. *
  348. * Accessed under msm_gpu::lock
  349. */
  350. char *comm;
  351. /**
  352. * @cmdline: Overridden task cmdline, see MSM_PARAM_CMDLINE
  353. *
  354. * Accessed under msm_gpu::lock
  355. */
  356. char *cmdline;
  357. /**
  358. * @elapsed_ns:
  359. * The total (cumulative) elapsed time GPU was busy with rendering
  360. * from this context in ns.
  361. */
  362. uint64_t elapsed_ns;
  363. /**
  364. * @cycles:
  365. * The total (cumulative) GPU cycles elapsed attributed to this
  366. * context.
  367. */
  368. uint64_t cycles;
  369. /**
  370. * @entities:
  371. * Table of per-priority-level sched entities used by submitqueues
  372. * associated with this &drm_file. Because some userspace apps
  373. * make assumptions about rendering from multiple gl contexts
  374. * (of the same priority) within the process happening in FIFO
  375. * order without requiring any fencing beyond MakeCurrent(), we
  376. * create at most one &drm_sched_entity per-process per-priority-
  377. * level.
  378. */
  379. struct drm_sched_entity *entities[NR_SCHED_PRIORITIES * MSM_GPU_MAX_RINGS];
  380. /**
  381. * @ctx_mem:
  382. * Total amount of memory of GEM buffers with handles attached for
  383. * this context.
  384. */
  385. atomic64_t ctx_mem;
  386. };
  387. struct drm_gpuvm *msm_context_vm(struct drm_device *dev, struct msm_context *ctx);
  388. /**
  389. * msm_context_is_vmbind() - has userspace opted in to VM_BIND?
  390. *
  391. * @ctx: the drm_file context
  392. *
  393. * See MSM_PARAM_EN_VM_BIND. If userspace is managing the VM, it can
  394. * do sparse binding including having multiple, potentially partial,
  395. * mappings in the VM. Therefore certain legacy uabi (ie. GET_IOVA,
  396. * SET_IOVA) are rejected because they don't have a sensible meaning.
  397. *
  398. * Returns: %true if userspace is managing the VM, %false otherwise.
  399. */
  400. static inline bool
  401. msm_context_is_vmbind(struct msm_context *ctx)
  402. {
  403. return ctx->userspace_managed_vm;
  404. }
  405. /**
  406. * msm_gpu_convert_priority - Map userspace priority to ring # and sched priority
  407. *
  408. * @gpu: the gpu instance
  409. * @prio: the userspace priority level
  410. * @ring_nr: [out] the ringbuffer the userspace priority maps to
  411. * @sched_prio: [out] the gpu scheduler priority level which the userspace
  412. * priority maps to
  413. *
  414. * With drm/scheduler providing it's own level of prioritization, our total
  415. * number of available priority levels is (nr_rings * NR_SCHED_PRIORITIES).
  416. * Each ring is associated with it's own scheduler instance. However, our
  417. * UABI is that lower numerical values are higher priority. So mapping the
  418. * single userspace priority level into ring_nr and sched_prio takes some
  419. * care. The userspace provided priority (when a submitqueue is created)
  420. * is mapped to ring nr and scheduler priority as such:
  421. *
  422. * ring_nr = userspace_prio / NR_SCHED_PRIORITIES
  423. * sched_prio = NR_SCHED_PRIORITIES -
  424. * (userspace_prio % NR_SCHED_PRIORITIES) - 1
  425. *
  426. * This allows generations without preemption (nr_rings==1) to have some
  427. * amount of prioritization, and provides more priority levels for gens
  428. * that do have preemption.
  429. *
  430. * Returns: %0 on success, %-errno on error.
  431. */
  432. static inline int msm_gpu_convert_priority(struct msm_gpu *gpu, int prio,
  433. unsigned *ring_nr, enum drm_sched_priority *sched_prio)
  434. {
  435. unsigned rn, sp;
  436. rn = div_u64_rem(prio, NR_SCHED_PRIORITIES, &sp);
  437. /* invert sched priority to map to higher-numeric-is-higher-
  438. * priority convention
  439. */
  440. sp = NR_SCHED_PRIORITIES - sp - 1;
  441. if (rn >= gpu->nr_rings)
  442. return -EINVAL;
  443. *ring_nr = rn;
  444. *sched_prio = sp;
  445. return 0;
  446. }
  447. /**
  448. * struct msm_gpu_submitqueue - Userspace created context.
  449. *
  450. * A submitqueue is associated with a gl context or vk queue (or equiv)
  451. * in userspace.
  452. *
  453. * @id: userspace id for the submitqueue, unique within the drm_file
  454. * @flags: userspace flags for the submitqueue, specified at creation
  455. * (currently unusued)
  456. * @ring_nr: the ringbuffer used by this submitqueue, which is determined
  457. * by the submitqueue's priority
  458. * @faults: the number of GPU hangs associated with this submitqueue
  459. * @last_fence: the sequence number of the last allocated fence (for error
  460. * checking)
  461. * @ctx: the per-drm_file context associated with the submitqueue (ie.
  462. * which set of pgtables do submits jobs associated with the
  463. * submitqueue use)
  464. * @node: node in the context's list of submitqueues
  465. * @fence_idr: maps fence-id to dma_fence for userspace visible fence
  466. * seqno, protected by submitqueue lock
  467. * @idr_lock: for serializing access to fence_idr
  468. * @lock: submitqueue lock for serializing submits on a queue
  469. * @ref: reference count
  470. * @entity: the submit job-queue
  471. */
  472. struct msm_gpu_submitqueue {
  473. int id;
  474. u32 flags;
  475. u32 ring_nr;
  476. int faults;
  477. uint32_t last_fence;
  478. struct msm_context *ctx;
  479. struct list_head node;
  480. struct idr fence_idr;
  481. struct spinlock idr_lock;
  482. struct mutex lock;
  483. struct kref ref;
  484. struct drm_sched_entity *entity;
  485. /** @_vm_bind_entity: used for @entity pointer for VM_BIND queues */
  486. struct drm_sched_entity _vm_bind_entity[0];
  487. };
  488. struct msm_gpu_state_bo {
  489. u64 iova;
  490. size_t size;
  491. u32 flags;
  492. void *data;
  493. bool encoded;
  494. char name[32];
  495. };
  496. struct msm_gpu_state {
  497. struct kref ref;
  498. struct timespec64 time;
  499. struct {
  500. u64 iova;
  501. u32 fence;
  502. u32 seqno;
  503. u32 rptr;
  504. u32 wptr;
  505. void *data;
  506. int data_size;
  507. bool encoded;
  508. } ring[MSM_GPU_MAX_RINGS];
  509. int nr_registers;
  510. u32 *registers;
  511. u32 rbbm_status;
  512. char *comm;
  513. char *cmd;
  514. struct msm_gpu_fault_info fault_info;
  515. int nr_vm_logs;
  516. struct msm_gem_vm_log_entry *vm_logs;
  517. int nr_bos;
  518. struct msm_gpu_state_bo *bos;
  519. };
  520. static inline void gpu_write(struct msm_gpu *gpu, u32 reg, u32 data)
  521. {
  522. trace_msm_gpu_regaccess(reg);
  523. writel(data, gpu->mmio + (reg << 2));
  524. }
  525. static inline u32 gpu_read(struct msm_gpu *gpu, u32 reg)
  526. {
  527. trace_msm_gpu_regaccess(reg);
  528. return readl(gpu->mmio + (reg << 2));
  529. }
  530. static inline void gpu_rmw(struct msm_gpu *gpu, u32 reg, u32 mask, u32 or)
  531. {
  532. trace_msm_gpu_regaccess(reg);
  533. msm_rmw(gpu->mmio + (reg << 2), mask, or);
  534. }
  535. static inline u64 gpu_read64(struct msm_gpu *gpu, u32 reg)
  536. {
  537. u64 val;
  538. /*
  539. * Why not a readq here? Two reasons: 1) many of the LO registers are
  540. * not quad word aligned and 2) the GPU hardware designers have a bit
  541. * of a history of putting registers where they fit, especially in
  542. * spins. The longer a GPU family goes the higher the chance that
  543. * we'll get burned. We could do a series of validity checks if we
  544. * wanted to, but really is a readq() that much better? Nah.
  545. */
  546. /*
  547. * For some lo/hi registers (like perfcounters), the hi value is latched
  548. * when the lo is read, so make sure to read the lo first to trigger
  549. * that
  550. */
  551. trace_msm_gpu_regaccess(reg);
  552. val = (u64) readl(gpu->mmio + (reg << 2));
  553. trace_msm_gpu_regaccess(reg+1);
  554. val |= ((u64) readl(gpu->mmio + ((reg + 1) << 2)) << 32);
  555. return val;
  556. }
  557. static inline void gpu_write64(struct msm_gpu *gpu, u32 reg, u64 val)
  558. {
  559. trace_msm_gpu_regaccess(reg);
  560. /* Why not a writeq here? Read the screed above */
  561. writel(lower_32_bits(val), gpu->mmio + (reg << 2));
  562. trace_msm_gpu_regaccess(reg+1);
  563. writel(upper_32_bits(val), gpu->mmio + ((reg + 1) << 2));
  564. }
  565. int msm_gpu_pm_suspend(struct msm_gpu *gpu);
  566. int msm_gpu_pm_resume(struct msm_gpu *gpu);
  567. void msm_gpu_show_fdinfo(struct msm_gpu *gpu, struct msm_context *ctx,
  568. struct drm_printer *p);
  569. int msm_submitqueue_init(struct drm_device *drm, struct msm_context *ctx);
  570. struct msm_gpu_submitqueue *msm_submitqueue_get(struct msm_context *ctx,
  571. u32 id);
  572. int msm_submitqueue_create(struct drm_device *drm,
  573. struct msm_context *ctx,
  574. u32 prio, u32 flags, u32 *id);
  575. int msm_submitqueue_query(struct drm_device *drm, struct msm_context *ctx,
  576. struct drm_msm_submitqueue_query *args);
  577. int msm_submitqueue_remove(struct msm_context *ctx, u32 id);
  578. void msm_submitqueue_close(struct msm_context *ctx);
  579. void msm_submitqueue_destroy(struct kref *kref);
  580. int msm_context_set_sysprof(struct msm_context *ctx, struct msm_gpu *gpu, int sysprof);
  581. void __msm_context_destroy(struct kref *kref);
  582. static inline void msm_context_put(struct msm_context *ctx)
  583. {
  584. kref_put(&ctx->ref, __msm_context_destroy);
  585. }
  586. static inline struct msm_context *msm_context_get(
  587. struct msm_context *ctx)
  588. {
  589. kref_get(&ctx->ref);
  590. return ctx;
  591. }
  592. void msm_devfreq_init(struct msm_gpu *gpu);
  593. void msm_devfreq_cleanup(struct msm_gpu *gpu);
  594. void msm_devfreq_resume(struct msm_gpu *gpu);
  595. void msm_devfreq_suspend(struct msm_gpu *gpu);
  596. void msm_devfreq_boost(struct msm_gpu *gpu, unsigned factor);
  597. void msm_devfreq_active(struct msm_gpu *gpu);
  598. void msm_devfreq_idle(struct msm_gpu *gpu);
  599. int msm_gpu_hw_init(struct msm_gpu *gpu);
  600. void msm_gpu_perfcntr_start(struct msm_gpu *gpu);
  601. void msm_gpu_perfcntr_stop(struct msm_gpu *gpu);
  602. int msm_gpu_perfcntr_sample(struct msm_gpu *gpu, uint32_t *activetime,
  603. uint32_t *totaltime, uint32_t ncntrs, uint32_t *cntrs);
  604. void msm_gpu_retire(struct msm_gpu *gpu);
  605. void msm_gpu_submit(struct msm_gpu *gpu, struct msm_gem_submit *submit);
  606. int msm_gpu_init(struct drm_device *drm, struct platform_device *pdev,
  607. struct msm_gpu *gpu, const struct msm_gpu_funcs *funcs,
  608. const char *name, struct msm_gpu_config *config);
  609. struct drm_gpuvm *
  610. msm_gpu_create_private_vm(struct msm_gpu *gpu, struct task_struct *task,
  611. bool kernel_managed);
  612. void msm_gpu_cleanup(struct msm_gpu *gpu);
  613. struct msm_gpu *adreno_load_gpu(struct drm_device *dev);
  614. bool adreno_has_gpu(struct device_node *node);
  615. void __init adreno_register(void);
  616. void __exit adreno_unregister(void);
  617. static inline void msm_submitqueue_put(struct msm_gpu_submitqueue *queue)
  618. {
  619. if (queue)
  620. kref_put(&queue->ref, msm_submitqueue_destroy);
  621. }
  622. static inline struct msm_gpu_state *msm_gpu_crashstate_get(struct msm_gpu *gpu)
  623. {
  624. struct msm_gpu_state *state = NULL;
  625. mutex_lock(&gpu->lock);
  626. if (gpu->crashstate) {
  627. kref_get(&gpu->crashstate->ref);
  628. state = gpu->crashstate;
  629. }
  630. mutex_unlock(&gpu->lock);
  631. return state;
  632. }
  633. static inline void msm_gpu_crashstate_put(struct msm_gpu *gpu)
  634. {
  635. mutex_lock(&gpu->lock);
  636. if (gpu->crashstate) {
  637. if (gpu->funcs->gpu_state_put(gpu->crashstate))
  638. gpu->crashstate = NULL;
  639. }
  640. mutex_unlock(&gpu->lock);
  641. }
  642. void msm_gpu_fault_crashstate_capture(struct msm_gpu *gpu, struct msm_gpu_fault_info *fault_info);
  643. /*
  644. * Simple macro to semi-cleanly add the MAP_PRIV flag for targets that can
  645. * support expanded privileges
  646. */
  647. #define check_apriv(gpu, flags) \
  648. (((gpu)->hw_apriv ? MSM_BO_MAP_PRIV : 0) | (flags))
  649. #endif /* __MSM_GPU_H__ */