Lines Matching refs:gpu
27 struct msm_gpu *gpu = platform_get_drvdata(to_platform_device(dev)); in msm_devfreq_target() local
35 if (gpu->funcs->gpu_set_freq) in msm_devfreq_target()
36 gpu->funcs->gpu_set_freq(gpu, (u64)*freq); in msm_devfreq_target()
38 clk_set_rate(gpu->core_clk, *freq); in msm_devfreq_target()
48 struct msm_gpu *gpu = platform_get_drvdata(to_platform_device(dev)); in msm_devfreq_get_dev_status() local
51 if (gpu->funcs->gpu_get_freq) in msm_devfreq_get_dev_status()
52 status->current_frequency = gpu->funcs->gpu_get_freq(gpu); in msm_devfreq_get_dev_status()
54 status->current_frequency = clk_get_rate(gpu->core_clk); in msm_devfreq_get_dev_status()
56 status->busy_time = gpu->funcs->gpu_busy(gpu); in msm_devfreq_get_dev_status()
59 status->total_time = ktime_us_delta(time, gpu->devfreq.time); in msm_devfreq_get_dev_status()
60 gpu->devfreq.time = time; in msm_devfreq_get_dev_status()
67 struct msm_gpu *gpu = platform_get_drvdata(to_platform_device(dev)); in msm_devfreq_get_cur_freq() local
69 if (gpu->funcs->gpu_get_freq) in msm_devfreq_get_cur_freq()
70 *freq = gpu->funcs->gpu_get_freq(gpu); in msm_devfreq_get_cur_freq()
72 *freq = clk_get_rate(gpu->core_clk); in msm_devfreq_get_cur_freq()
84 static void msm_devfreq_init(struct msm_gpu *gpu) in msm_devfreq_init() argument
87 if (!gpu->funcs->gpu_busy) in msm_devfreq_init()
90 msm_devfreq_profile.initial_freq = gpu->fast_rate; in msm_devfreq_init()
97 gpu->devfreq.devfreq = devm_devfreq_add_device(&gpu->pdev->dev, in msm_devfreq_init()
101 if (IS_ERR(gpu->devfreq.devfreq)) { in msm_devfreq_init()
102 DRM_DEV_ERROR(&gpu->pdev->dev, "Couldn't initialize GPU devfreq\n"); in msm_devfreq_init()
103 gpu->devfreq.devfreq = NULL; in msm_devfreq_init()
106 devfreq_suspend_device(gpu->devfreq.devfreq); in msm_devfreq_init()
109 static int enable_pwrrail(struct msm_gpu *gpu) in enable_pwrrail() argument
111 struct drm_device *dev = gpu->dev; in enable_pwrrail()
114 if (gpu->gpu_reg) { in enable_pwrrail()
115 ret = regulator_enable(gpu->gpu_reg); in enable_pwrrail()
122 if (gpu->gpu_cx) { in enable_pwrrail()
123 ret = regulator_enable(gpu->gpu_cx); in enable_pwrrail()
133 static int disable_pwrrail(struct msm_gpu *gpu) in disable_pwrrail() argument
135 if (gpu->gpu_cx) in disable_pwrrail()
136 regulator_disable(gpu->gpu_cx); in disable_pwrrail()
137 if (gpu->gpu_reg) in disable_pwrrail()
138 regulator_disable(gpu->gpu_reg); in disable_pwrrail()
142 static int enable_clk(struct msm_gpu *gpu) in enable_clk() argument
144 if (gpu->core_clk && gpu->fast_rate) in enable_clk()
145 clk_set_rate(gpu->core_clk, gpu->fast_rate); in enable_clk()
148 if (gpu->rbbmtimer_clk) in enable_clk()
149 clk_set_rate(gpu->rbbmtimer_clk, 19200000); in enable_clk()
151 return clk_bulk_prepare_enable(gpu->nr_clocks, gpu->grp_clks); in enable_clk()
154 static int disable_clk(struct msm_gpu *gpu) in disable_clk() argument
156 clk_bulk_disable_unprepare(gpu->nr_clocks, gpu->grp_clks); in disable_clk()
163 if (gpu->core_clk) in disable_clk()
164 clk_set_rate(gpu->core_clk, 27000000); in disable_clk()
166 if (gpu->rbbmtimer_clk) in disable_clk()
167 clk_set_rate(gpu->rbbmtimer_clk, 0); in disable_clk()
172 static int enable_axi(struct msm_gpu *gpu) in enable_axi() argument
174 if (gpu->ebi1_clk) in enable_axi()
175 clk_prepare_enable(gpu->ebi1_clk); in enable_axi()
179 static int disable_axi(struct msm_gpu *gpu) in disable_axi() argument
181 if (gpu->ebi1_clk) in disable_axi()
182 clk_disable_unprepare(gpu->ebi1_clk); in disable_axi()
186 void msm_gpu_resume_devfreq(struct msm_gpu *gpu) in msm_gpu_resume_devfreq() argument
188 gpu->devfreq.busy_cycles = 0; in msm_gpu_resume_devfreq()
189 gpu->devfreq.time = ktime_get(); in msm_gpu_resume_devfreq()
191 devfreq_resume_device(gpu->devfreq.devfreq); in msm_gpu_resume_devfreq()
194 int msm_gpu_pm_resume(struct msm_gpu *gpu) in msm_gpu_pm_resume() argument
198 DBG("%s", gpu->name); in msm_gpu_pm_resume()
200 ret = enable_pwrrail(gpu); in msm_gpu_pm_resume()
204 ret = enable_clk(gpu); in msm_gpu_pm_resume()
208 ret = enable_axi(gpu); in msm_gpu_pm_resume()
212 msm_gpu_resume_devfreq(gpu); in msm_gpu_pm_resume()
214 gpu->needs_hw_init = true; in msm_gpu_pm_resume()
219 int msm_gpu_pm_suspend(struct msm_gpu *gpu) in msm_gpu_pm_suspend() argument
223 DBG("%s", gpu->name); in msm_gpu_pm_suspend()
225 devfreq_suspend_device(gpu->devfreq.devfreq); in msm_gpu_pm_suspend()
227 ret = disable_axi(gpu); in msm_gpu_pm_suspend()
231 ret = disable_clk(gpu); in msm_gpu_pm_suspend()
235 ret = disable_pwrrail(gpu); in msm_gpu_pm_suspend()
242 int msm_gpu_hw_init(struct msm_gpu *gpu) in msm_gpu_hw_init() argument
246 WARN_ON(!mutex_is_locked(&gpu->dev->struct_mutex)); in msm_gpu_hw_init()
248 if (!gpu->needs_hw_init) in msm_gpu_hw_init()
251 disable_irq(gpu->irq); in msm_gpu_hw_init()
252 ret = gpu->funcs->hw_init(gpu); in msm_gpu_hw_init()
254 gpu->needs_hw_init = false; in msm_gpu_hw_init()
255 enable_irq(gpu->irq); in msm_gpu_hw_init()
264 struct msm_gpu *gpu = data; in msm_gpu_devcoredump_read() local
269 state = msm_gpu_crashstate_get(gpu); in msm_gpu_devcoredump_read()
290 gpu->funcs->show(gpu, state, &p); in msm_gpu_devcoredump_read()
292 msm_gpu_crashstate_put(gpu); in msm_gpu_devcoredump_read()
299 struct msm_gpu *gpu = data; in msm_gpu_devcoredump_free() local
301 msm_gpu_crashstate_put(gpu); in msm_gpu_devcoredump_free()
335 static void msm_gpu_crashstate_capture(struct msm_gpu *gpu, in msm_gpu_crashstate_capture() argument
341 if (!gpu->funcs->gpu_state_get) in msm_gpu_crashstate_capture()
345 if (gpu->crashstate) in msm_gpu_crashstate_capture()
348 state = gpu->funcs->gpu_state_get(gpu); in msm_gpu_crashstate_capture()
371 gpu->crashstate = state; in msm_gpu_crashstate_capture()
374 dev_coredumpm(gpu->dev->dev, THIS_MODULE, gpu, 0, GFP_KERNEL, in msm_gpu_crashstate_capture()
378 static void msm_gpu_crashstate_capture(struct msm_gpu *gpu, in msm_gpu_crashstate_capture() argument
388 static void update_fences(struct msm_gpu *gpu, struct msm_ringbuffer *ring, in update_fences() argument
407 WARN_ON(!mutex_is_locked(&ring->gpu->dev->struct_mutex)); in find_submit()
416 static void retire_submits(struct msm_gpu *gpu);
420 struct msm_gpu *gpu = container_of(work, struct msm_gpu, recover_work); in recover_worker() local
421 struct drm_device *dev = gpu->dev; in recover_worker()
424 struct msm_ringbuffer *cur_ring = gpu->funcs->active_ring(gpu); in recover_worker()
430 DRM_DEV_ERROR(dev->dev, "%s: hangcheck recover!\n", gpu->name); in recover_worker()
437 gpu->global_faults++; in recover_worker()
449 gpu->name, comm, cmd); in recover_worker()
458 pm_runtime_get_sync(&gpu->pdev->dev); in recover_worker()
459 msm_gpu_crashstate_capture(gpu, submit, comm, cmd); in recover_worker()
460 pm_runtime_put_sync(&gpu->pdev->dev); in recover_worker()
470 for (i = 0; i < gpu->nr_rings; i++) { in recover_worker()
471 struct msm_ringbuffer *ring = gpu->rb[i]; in recover_worker()
482 update_fences(gpu, ring, fence); in recover_worker()
485 if (msm_gpu_active(gpu)) { in recover_worker()
487 retire_submits(gpu); in recover_worker()
489 pm_runtime_get_sync(&gpu->pdev->dev); in recover_worker()
490 gpu->funcs->recover(gpu); in recover_worker()
491 pm_runtime_put_sync(&gpu->pdev->dev); in recover_worker()
497 for (i = 0; i < gpu->nr_rings; i++) { in recover_worker()
498 struct msm_ringbuffer *ring = gpu->rb[i]; in recover_worker()
501 gpu->funcs->submit(gpu, submit, NULL); in recover_worker()
507 msm_gpu_retire(gpu); in recover_worker()
510 static void hangcheck_timer_reset(struct msm_gpu *gpu) in hangcheck_timer_reset() argument
512 DBG("%s", gpu->name); in hangcheck_timer_reset()
513 mod_timer(&gpu->hangcheck_timer, in hangcheck_timer_reset()
519 struct msm_gpu *gpu = from_timer(gpu, t, hangcheck_timer); in hangcheck_handler() local
520 struct drm_device *dev = gpu->dev; in hangcheck_handler()
522 struct msm_ringbuffer *ring = gpu->funcs->active_ring(gpu); in hangcheck_handler()
532 gpu->name, ring->id); in hangcheck_handler()
534 gpu->name, fence); in hangcheck_handler()
536 gpu->name, ring->seqno); in hangcheck_handler()
538 queue_work(priv->wq, &gpu->recover_work); in hangcheck_handler()
543 hangcheck_timer_reset(gpu); in hangcheck_handler()
546 queue_work(priv->wq, &gpu->retire_work); in hangcheck_handler()
554 static int update_hw_cntrs(struct msm_gpu *gpu, uint32_t ncntrs, uint32_t *cntrs) in update_hw_cntrs() argument
556 uint32_t current_cntrs[ARRAY_SIZE(gpu->last_cntrs)]; in update_hw_cntrs()
557 int i, n = min(ncntrs, gpu->num_perfcntrs); in update_hw_cntrs()
560 for (i = 0; i < gpu->num_perfcntrs; i++) in update_hw_cntrs()
561 current_cntrs[i] = gpu_read(gpu, gpu->perfcntrs[i].sample_reg); in update_hw_cntrs()
565 cntrs[i] = current_cntrs[i] - gpu->last_cntrs[i]; in update_hw_cntrs()
568 for (i = 0; i < gpu->num_perfcntrs; i++) in update_hw_cntrs()
569 gpu->last_cntrs[i] = current_cntrs[i]; in update_hw_cntrs()
574 static void update_sw_cntrs(struct msm_gpu *gpu) in update_sw_cntrs() argument
580 spin_lock_irqsave(&gpu->perf_lock, flags); in update_sw_cntrs()
581 if (!gpu->perfcntr_active) in update_sw_cntrs()
585 elapsed = ktime_to_us(ktime_sub(time, gpu->last_sample.time)); in update_sw_cntrs()
587 gpu->totaltime += elapsed; in update_sw_cntrs()
588 if (gpu->last_sample.active) in update_sw_cntrs()
589 gpu->activetime += elapsed; in update_sw_cntrs()
591 gpu->last_sample.active = msm_gpu_active(gpu); in update_sw_cntrs()
592 gpu->last_sample.time = time; in update_sw_cntrs()
595 spin_unlock_irqrestore(&gpu->perf_lock, flags); in update_sw_cntrs()
598 void msm_gpu_perfcntr_start(struct msm_gpu *gpu) in msm_gpu_perfcntr_start() argument
602 pm_runtime_get_sync(&gpu->pdev->dev); in msm_gpu_perfcntr_start()
604 spin_lock_irqsave(&gpu->perf_lock, flags); in msm_gpu_perfcntr_start()
606 gpu->last_sample.active = msm_gpu_active(gpu); in msm_gpu_perfcntr_start()
607 gpu->last_sample.time = ktime_get(); in msm_gpu_perfcntr_start()
608 gpu->activetime = gpu->totaltime = 0; in msm_gpu_perfcntr_start()
609 gpu->perfcntr_active = true; in msm_gpu_perfcntr_start()
610 update_hw_cntrs(gpu, 0, NULL); in msm_gpu_perfcntr_start()
611 spin_unlock_irqrestore(&gpu->perf_lock, flags); in msm_gpu_perfcntr_start()
614 void msm_gpu_perfcntr_stop(struct msm_gpu *gpu) in msm_gpu_perfcntr_stop() argument
616 gpu->perfcntr_active = false; in msm_gpu_perfcntr_stop()
617 pm_runtime_put_sync(&gpu->pdev->dev); in msm_gpu_perfcntr_stop()
621 int msm_gpu_perfcntr_sample(struct msm_gpu *gpu, uint32_t *activetime, in msm_gpu_perfcntr_sample() argument
627 spin_lock_irqsave(&gpu->perf_lock, flags); in msm_gpu_perfcntr_sample()
629 if (!gpu->perfcntr_active) { in msm_gpu_perfcntr_sample()
634 *activetime = gpu->activetime; in msm_gpu_perfcntr_sample()
635 *totaltime = gpu->totaltime; in msm_gpu_perfcntr_sample()
637 gpu->activetime = gpu->totaltime = 0; in msm_gpu_perfcntr_sample()
639 ret = update_hw_cntrs(gpu, ncntrs, cntrs); in msm_gpu_perfcntr_sample()
642 spin_unlock_irqrestore(&gpu->perf_lock, flags); in msm_gpu_perfcntr_sample()
651 static void retire_submit(struct msm_gpu *gpu, struct msm_ringbuffer *ring, in retire_submit() argument
681 pm_runtime_mark_last_busy(&gpu->pdev->dev); in retire_submit()
682 pm_runtime_put_autosuspend(&gpu->pdev->dev); in retire_submit()
686 static void retire_submits(struct msm_gpu *gpu) in retire_submits() argument
688 struct drm_device *dev = gpu->dev; in retire_submits()
695 for (i = 0; i < gpu->nr_rings; i++) { in retire_submits()
696 struct msm_ringbuffer *ring = gpu->rb[i]; in retire_submits()
700 retire_submit(gpu, ring, submit); in retire_submits()
707 struct msm_gpu *gpu = container_of(work, struct msm_gpu, retire_work); in retire_worker() local
708 struct drm_device *dev = gpu->dev; in retire_worker()
711 for (i = 0; i < gpu->nr_rings; i++) in retire_worker()
712 update_fences(gpu, gpu->rb[i], gpu->rb[i]->memptrs->fence); in retire_worker()
715 retire_submits(gpu); in retire_worker()
720 void msm_gpu_retire(struct msm_gpu *gpu) in msm_gpu_retire() argument
722 struct msm_drm_private *priv = gpu->dev->dev_private; in msm_gpu_retire()
723 queue_work(priv->wq, &gpu->retire_work); in msm_gpu_retire()
724 update_sw_cntrs(gpu); in msm_gpu_retire()
728 void msm_gpu_submit(struct msm_gpu *gpu, struct msm_gem_submit *submit, in msm_gpu_submit() argument
731 struct drm_device *dev = gpu->dev; in msm_gpu_submit()
738 pm_runtime_get_sync(&gpu->pdev->dev); in msm_gpu_submit()
740 msm_gpu_hw_init(gpu); in msm_gpu_submit()
748 update_sw_cntrs(gpu); in msm_gpu_submit()
757 WARN_ON(is_active(msm_obj) && (msm_obj->gpu != gpu)); in msm_gpu_submit()
764 msm_gem_move_to_active(&msm_obj->base, gpu, true, submit->fence); in msm_gpu_submit()
766 msm_gem_move_to_active(&msm_obj->base, gpu, false, submit->fence); in msm_gpu_submit()
769 gpu->funcs->submit(gpu, submit, ctx); in msm_gpu_submit()
772 hangcheck_timer_reset(gpu); in msm_gpu_submit()
781 struct msm_gpu *gpu = data; in irq_handler() local
782 return gpu->funcs->irq(gpu); in irq_handler()
785 static int get_clocks(struct platform_device *pdev, struct msm_gpu *gpu) in get_clocks() argument
787 int ret = devm_clk_bulk_get_all(&pdev->dev, &gpu->grp_clks); in get_clocks()
790 gpu->nr_clocks = 0; in get_clocks()
794 gpu->nr_clocks = ret; in get_clocks()
796 gpu->core_clk = msm_clk_bulk_get_clock(gpu->grp_clks, in get_clocks()
797 gpu->nr_clocks, "core"); in get_clocks()
799 gpu->rbbmtimer_clk = msm_clk_bulk_get_clock(gpu->grp_clks, in get_clocks()
800 gpu->nr_clocks, "rbbmtimer"); in get_clocks()
806 msm_gpu_create_address_space(struct msm_gpu *gpu, struct platform_device *pdev, in msm_gpu_create_address_space() argument
817 if (!adreno_is_a2xx(to_adreno_gpu(gpu))) { in msm_gpu_create_address_space()
825 DRM_DEV_INFO(gpu->dev->dev, "%s: using IOMMU\n", gpu->name); in msm_gpu_create_address_space()
831 aspace = msm_gem_address_space_create_a2xx(&pdev->dev, gpu, "gpu", in msm_gpu_create_address_space()
836 DRM_DEV_ERROR(gpu->dev->dev, "failed to init mmu: %ld\n", in msm_gpu_create_address_space()
851 struct msm_gpu *gpu, const struct msm_gpu_funcs *funcs, in msm_gpu_init() argument
858 if (WARN_ON(gpu->num_perfcntrs > ARRAY_SIZE(gpu->last_cntrs))) in msm_gpu_init()
859 gpu->num_perfcntrs = ARRAY_SIZE(gpu->last_cntrs); in msm_gpu_init()
861 gpu->dev = drm; in msm_gpu_init()
862 gpu->funcs = funcs; in msm_gpu_init()
863 gpu->name = name; in msm_gpu_init()
865 INIT_LIST_HEAD(&gpu->active_list); in msm_gpu_init()
866 INIT_WORK(&gpu->retire_work, retire_worker); in msm_gpu_init()
867 INIT_WORK(&gpu->recover_work, recover_worker); in msm_gpu_init()
870 timer_setup(&gpu->hangcheck_timer, hangcheck_handler, 0); in msm_gpu_init()
872 spin_lock_init(&gpu->perf_lock); in msm_gpu_init()
876 gpu->mmio = msm_ioremap(pdev, config->ioname, name); in msm_gpu_init()
877 if (IS_ERR(gpu->mmio)) { in msm_gpu_init()
878 ret = PTR_ERR(gpu->mmio); in msm_gpu_init()
883 gpu->irq = platform_get_irq(pdev, 0); in msm_gpu_init()
884 if (gpu->irq < 0) { in msm_gpu_init()
885 ret = gpu->irq; in msm_gpu_init()
890 ret = devm_request_irq(&pdev->dev, gpu->irq, irq_handler, in msm_gpu_init()
891 IRQF_TRIGGER_HIGH, gpu->name, gpu); in msm_gpu_init()
893 DRM_DEV_ERROR(drm->dev, "failed to request IRQ%u: %d\n", gpu->irq, ret); in msm_gpu_init()
897 ret = get_clocks(pdev, gpu); in msm_gpu_init()
901 gpu->ebi1_clk = msm_clk_get(pdev, "bus"); in msm_gpu_init()
902 DBG("ebi1_clk: %p", gpu->ebi1_clk); in msm_gpu_init()
903 if (IS_ERR(gpu->ebi1_clk)) in msm_gpu_init()
904 gpu->ebi1_clk = NULL; in msm_gpu_init()
907 gpu->gpu_reg = devm_regulator_get(&pdev->dev, "vdd"); in msm_gpu_init()
908 DBG("gpu_reg: %p", gpu->gpu_reg); in msm_gpu_init()
909 if (IS_ERR(gpu->gpu_reg)) in msm_gpu_init()
910 gpu->gpu_reg = NULL; in msm_gpu_init()
912 gpu->gpu_cx = devm_regulator_get(&pdev->dev, "vddcx"); in msm_gpu_init()
913 DBG("gpu_cx: %p", gpu->gpu_cx); in msm_gpu_init()
914 if (IS_ERR(gpu->gpu_cx)) in msm_gpu_init()
915 gpu->gpu_cx = NULL; in msm_gpu_init()
917 gpu->pdev = pdev; in msm_gpu_init()
918 platform_set_drvdata(pdev, gpu); in msm_gpu_init()
920 msm_devfreq_init(gpu); in msm_gpu_init()
922 gpu->aspace = msm_gpu_create_address_space(gpu, pdev, in msm_gpu_init()
925 if (gpu->aspace == NULL) in msm_gpu_init()
927 else if (IS_ERR(gpu->aspace)) { in msm_gpu_init()
928 ret = PTR_ERR(gpu->aspace); in msm_gpu_init()
934 MSM_BO_UNCACHED, gpu->aspace, &gpu->memptrs_bo, in msm_gpu_init()
943 msm_gem_object_set_name(gpu->memptrs_bo, "memptrs"); in msm_gpu_init()
945 if (nr_rings > ARRAY_SIZE(gpu->rb)) { in msm_gpu_init()
947 ARRAY_SIZE(gpu->rb)); in msm_gpu_init()
948 nr_rings = ARRAY_SIZE(gpu->rb); in msm_gpu_init()
953 gpu->rb[i] = msm_ringbuffer_new(gpu, i, memptrs, memptrs_iova); in msm_gpu_init()
955 if (IS_ERR(gpu->rb[i])) { in msm_gpu_init()
956 ret = PTR_ERR(gpu->rb[i]); in msm_gpu_init()
966 gpu->nr_rings = nr_rings; in msm_gpu_init()
971 for (i = 0; i < ARRAY_SIZE(gpu->rb); i++) { in msm_gpu_init()
972 msm_ringbuffer_destroy(gpu->rb[i]); in msm_gpu_init()
973 gpu->rb[i] = NULL; in msm_gpu_init()
976 msm_gem_kernel_put(gpu->memptrs_bo, gpu->aspace, false); in msm_gpu_init()
982 void msm_gpu_cleanup(struct msm_gpu *gpu) in msm_gpu_cleanup() argument
986 DBG("%s", gpu->name); in msm_gpu_cleanup()
988 WARN_ON(!list_empty(&gpu->active_list)); in msm_gpu_cleanup()
990 for (i = 0; i < ARRAY_SIZE(gpu->rb); i++) { in msm_gpu_cleanup()
991 msm_ringbuffer_destroy(gpu->rb[i]); in msm_gpu_cleanup()
992 gpu->rb[i] = NULL; in msm_gpu_cleanup()
995 msm_gem_kernel_put(gpu->memptrs_bo, gpu->aspace, false); in msm_gpu_cleanup()
997 if (!IS_ERR_OR_NULL(gpu->aspace)) { in msm_gpu_cleanup()
998 gpu->aspace->mmu->funcs->detach(gpu->aspace->mmu, in msm_gpu_cleanup()
1000 msm_gem_address_space_put(gpu->aspace); in msm_gpu_cleanup()