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