Lines Matching refs:vpu

218 static inline void vpu_cfg_writel(struct mtk_vpu *vpu, u32 val, u32 offset)  in vpu_cfg_writel()  argument
220 writel(val, vpu->reg.cfg + offset); in vpu_cfg_writel()
223 static inline u32 vpu_cfg_readl(struct mtk_vpu *vpu, u32 offset) in vpu_cfg_readl() argument
225 return readl(vpu->reg.cfg + offset); in vpu_cfg_readl()
228 static inline bool vpu_running(struct mtk_vpu *vpu) in vpu_running() argument
230 return vpu_cfg_readl(vpu, VPU_RESET) & BIT(0); in vpu_running()
233 static void vpu_clock_disable(struct mtk_vpu *vpu) in vpu_clock_disable() argument
236 mutex_lock(&vpu->vpu_mutex); in vpu_clock_disable()
237 if (!--vpu->wdt_refcnt) in vpu_clock_disable()
238 vpu_cfg_writel(vpu, in vpu_clock_disable()
239 vpu_cfg_readl(vpu, VPU_WDT_REG) & ~(1L << 31), in vpu_clock_disable()
241 mutex_unlock(&vpu->vpu_mutex); in vpu_clock_disable()
243 clk_disable(vpu->clk); in vpu_clock_disable()
246 static int vpu_clock_enable(struct mtk_vpu *vpu) in vpu_clock_enable() argument
250 ret = clk_enable(vpu->clk); in vpu_clock_enable()
254 mutex_lock(&vpu->vpu_mutex); in vpu_clock_enable()
255 if (!vpu->wdt_refcnt++) in vpu_clock_enable()
256 vpu_cfg_writel(vpu, in vpu_clock_enable()
257 vpu_cfg_readl(vpu, VPU_WDT_REG) | (1L << 31), in vpu_clock_enable()
259 mutex_unlock(&vpu->vpu_mutex); in vpu_clock_enable()
268 struct mtk_vpu *vpu = platform_get_drvdata(pdev); in vpu_ipi_register() local
271 if (!vpu) { in vpu_ipi_register()
277 ipi_desc = vpu->ipi_desc; in vpu_ipi_register()
294 struct mtk_vpu *vpu = platform_get_drvdata(pdev); in vpu_ipi_send() local
295 struct share_obj *send_obj = vpu->send_buf; in vpu_ipi_send()
301 dev_err(vpu->dev, "failed to send ipi message\n"); in vpu_ipi_send()
305 ret = vpu_clock_enable(vpu); in vpu_ipi_send()
307 dev_err(vpu->dev, "failed to enable vpu clock\n"); in vpu_ipi_send()
310 if (!vpu_running(vpu)) { in vpu_ipi_send()
311 dev_err(vpu->dev, "vpu_ipi_send: VPU is not running\n"); in vpu_ipi_send()
316 mutex_lock(&vpu->vpu_mutex); in vpu_ipi_send()
322 dev_err(vpu->dev, "vpu_ipi_send: IPI timeout!\n"); in vpu_ipi_send()
326 } while (vpu_cfg_readl(vpu, HOST_TO_VPU)); in vpu_ipi_send()
332 vpu->ipi_id_ack[id] = false; in vpu_ipi_send()
334 vpu_cfg_writel(vpu, 0x1, HOST_TO_VPU); in vpu_ipi_send()
336 mutex_unlock(&vpu->vpu_mutex); in vpu_ipi_send()
340 ret = wait_event_timeout(vpu->ack_wq, vpu->ipi_id_ack[id], timeout); in vpu_ipi_send()
341 vpu->ipi_id_ack[id] = false; in vpu_ipi_send()
343 dev_err(vpu->dev, "vpu ipi %d ack time out !", id); in vpu_ipi_send()
347 vpu_clock_disable(vpu); in vpu_ipi_send()
352 mutex_unlock(&vpu->vpu_mutex); in vpu_ipi_send()
354 vpu_clock_disable(vpu); in vpu_ipi_send()
363 struct mtk_vpu *vpu = container_of(wdt, struct mtk_vpu, wdt); in vpu_wdt_reset_func() local
367 dev_info(vpu->dev, "vpu reset\n"); in vpu_wdt_reset_func()
368 ret = vpu_clock_enable(vpu); in vpu_wdt_reset_func()
370 dev_err(vpu->dev, "[VPU] wdt enables clock failed %d\n", ret); in vpu_wdt_reset_func()
373 mutex_lock(&vpu->vpu_mutex); in vpu_wdt_reset_func()
374 vpu_cfg_writel(vpu, 0x0, VPU_RESET); in vpu_wdt_reset_func()
375 vpu->fw_loaded = false; in vpu_wdt_reset_func()
376 mutex_unlock(&vpu->vpu_mutex); in vpu_wdt_reset_func()
377 vpu_clock_disable(vpu); in vpu_wdt_reset_func()
382 dev_dbg(vpu->dev, "wdt handler func %d\n", index); in vpu_wdt_reset_func()
391 struct mtk_vpu *vpu = platform_get_drvdata(pdev); in vpu_wdt_reg_handler() local
394 if (!vpu) { in vpu_wdt_reg_handler()
399 handler = vpu->wdt.handler; in vpu_wdt_reg_handler()
402 dev_dbg(vpu->dev, "wdt register id %d\n", id); in vpu_wdt_reg_handler()
403 mutex_lock(&vpu->vpu_mutex); in vpu_wdt_reg_handler()
406 mutex_unlock(&vpu->vpu_mutex); in vpu_wdt_reg_handler()
410 dev_err(vpu->dev, "register vpu wdt handler failed\n"); in vpu_wdt_reg_handler()
417 struct mtk_vpu *vpu = platform_get_drvdata(pdev); in vpu_get_vdec_hw_capa() local
419 return vpu->run.dec_capability; in vpu_get_vdec_hw_capa()
425 struct mtk_vpu *vpu = platform_get_drvdata(pdev); in vpu_get_venc_hw_capa() local
427 return vpu->run.enc_capability; in vpu_get_venc_hw_capa()
434 struct mtk_vpu *vpu = platform_get_drvdata(pdev); in vpu_mapping_dm_addr() local
438 dev_err(vpu->dev, "invalid virtual data memory address\n"); in vpu_mapping_dm_addr()
443 return (__force void *)(dtcm_dmem_addr + vpu->reg.tcm + in vpu_mapping_dm_addr()
446 return vpu->extmem[D_FW].va + (dtcm_dmem_addr - VPU_DTCM_SIZE); in vpu_mapping_dm_addr()
474 static int load_requested_vpu(struct mtk_vpu *vpu, in load_requested_vpu() argument
486 ret = request_firmware(&vpu_fw, fw_name, vpu->dev); in load_requested_vpu()
488 dev_err(vpu->dev, "Failed to load %s, %d\n", fw_name, ret); in load_requested_vpu()
493 dev_err(vpu->dev, "fw %s size %zu is abnormal\n", fw_name, in load_requested_vpu()
498 dev_dbg(vpu->dev, "Downloaded fw %s size: %zu.\n", in load_requested_vpu()
502 vpu_cfg_writel(vpu, 0x0, VPU_RESET); in load_requested_vpu()
506 dev_dbg(vpu->dev, "fw size %zu > limited fw size %zu\n", in load_requested_vpu()
509 dev_dbg(vpu->dev, "extra_fw_size %zu\n", extra_fw_size); in load_requested_vpu()
512 dest = (__force void *)vpu->reg.tcm; in load_requested_vpu()
518 dest = vpu->extmem[fw_type].va; in load_requested_vpu()
519 dev_dbg(vpu->dev, "download extended memory type %x\n", in load_requested_vpu()
531 struct mtk_vpu *vpu; in vpu_load_firmware() local
541 vpu = platform_get_drvdata(pdev); in vpu_load_firmware()
542 run = &vpu->run; in vpu_load_firmware()
544 mutex_lock(&vpu->vpu_mutex); in vpu_load_firmware()
545 if (vpu->fw_loaded) { in vpu_load_firmware()
546 mutex_unlock(&vpu->vpu_mutex); in vpu_load_firmware()
549 mutex_unlock(&vpu->vpu_mutex); in vpu_load_firmware()
551 ret = vpu_clock_enable(vpu); in vpu_load_firmware()
557 mutex_lock(&vpu->vpu_mutex); in vpu_load_firmware()
560 dev_dbg(vpu->dev, "firmware request\n"); in vpu_load_firmware()
562 ret = load_requested_vpu(vpu, P_FW); in vpu_load_firmware()
569 ret = load_requested_vpu(vpu, D_FW); in vpu_load_firmware()
575 vpu->fw_loaded = true; in vpu_load_firmware()
577 vpu_cfg_writel(vpu, 0x1, VPU_RESET); in vpu_load_firmware()
596 mutex_unlock(&vpu->vpu_mutex); in vpu_load_firmware()
597 vpu_clock_disable(vpu); in vpu_load_firmware()
605 struct mtk_vpu *vpu = (struct mtk_vpu *)priv; in vpu_init_ipi_handler() local
608 vpu->run.signaled = run->signaled; in vpu_init_ipi_handler()
609 strscpy(vpu->run.fw_ver, run->fw_ver, sizeof(vpu->run.fw_ver)); in vpu_init_ipi_handler()
610 vpu->run.dec_capability = run->dec_capability; in vpu_init_ipi_handler()
611 vpu->run.enc_capability = run->enc_capability; in vpu_init_ipi_handler()
612 wake_up_interruptible(&vpu->run.wq); in vpu_init_ipi_handler()
624 struct mtk_vpu *vpu = dev_get_drvdata(dev); in vpu_debug_read() local
626 ret = vpu_clock_enable(vpu); in vpu_debug_read()
628 dev_err(vpu->dev, "[VPU] enable clock failed %d\n", ret); in vpu_debug_read()
633 running = vpu_running(vpu); in vpu_debug_read()
634 pc = vpu_cfg_readl(vpu, VPU_PC_REG); in vpu_debug_read()
635 wdt = vpu_cfg_readl(vpu, VPU_WDT_REG); in vpu_debug_read()
636 host_to_vpu = vpu_cfg_readl(vpu, HOST_TO_VPU); in vpu_debug_read()
637 vpu_to_host = vpu_cfg_readl(vpu, VPU_TO_HOST); in vpu_debug_read()
638 vpu_clock_disable(vpu); in vpu_debug_read()
647 vpu->run.fw_ver, pc, wdt, in vpu_debug_read()
662 static void vpu_free_ext_mem(struct mtk_vpu *vpu, u8 fw_type) in vpu_free_ext_mem() argument
664 struct device *dev = vpu->dev; in vpu_free_ext_mem()
667 dma_free_coherent(dev, fw_ext_size, vpu->extmem[fw_type].va, in vpu_free_ext_mem()
668 vpu->extmem[fw_type].pa); in vpu_free_ext_mem()
671 static int vpu_alloc_ext_mem(struct mtk_vpu *vpu, u32 fw_type) in vpu_alloc_ext_mem() argument
673 struct device *dev = vpu->dev; in vpu_alloc_ext_mem()
677 u32 offset_4gb = vpu->enable_4GB ? 0x40000000 : 0; in vpu_alloc_ext_mem()
679 vpu->extmem[fw_type].va = dma_alloc_coherent(dev, in vpu_alloc_ext_mem()
681 &vpu->extmem[fw_type].pa, in vpu_alloc_ext_mem()
683 if (!vpu->extmem[fw_type].va) { in vpu_alloc_ext_mem()
689 vpu_cfg_writel(vpu, 0x1, vpu_ext_mem0); in vpu_alloc_ext_mem()
690 vpu_cfg_writel(vpu, (vpu->extmem[fw_type].pa & 0xFFFFF000) + offset_4gb, in vpu_alloc_ext_mem()
695 (unsigned long long)vpu->extmem[fw_type].pa, in vpu_alloc_ext_mem()
696 vpu->extmem[fw_type].va); in vpu_alloc_ext_mem()
701 static void vpu_ipi_handler(struct mtk_vpu *vpu) in vpu_ipi_handler() argument
703 struct share_obj *rcv_obj = vpu->recv_buf; in vpu_ipi_handler()
704 struct vpu_ipi_desc *ipi_desc = vpu->ipi_desc; in vpu_ipi_handler()
711 vpu->ipi_id_ack[rcv_obj->id] = true; in vpu_ipi_handler()
712 wake_up(&vpu->ack_wq); in vpu_ipi_handler()
715 dev_err(vpu->dev, "No such ipi id = %d\n", rcv_obj->id); in vpu_ipi_handler()
719 static int vpu_ipi_init(struct mtk_vpu *vpu) in vpu_ipi_init() argument
722 vpu_cfg_writel(vpu, 0x0, VPU_TO_HOST); in vpu_ipi_init()
725 vpu->recv_buf = (__force struct share_obj *)(vpu->reg.tcm + in vpu_ipi_init()
727 vpu->send_buf = vpu->recv_buf + 1; in vpu_ipi_init()
728 memset(vpu->recv_buf, 0, sizeof(struct share_obj)); in vpu_ipi_init()
729 memset(vpu->send_buf, 0, sizeof(struct share_obj)); in vpu_ipi_init()
736 struct mtk_vpu *vpu = priv; in vpu_irq_handler() local
745 ret = clk_enable(vpu->clk); in vpu_irq_handler()
747 dev_err(vpu->dev, "[VPU] enable clock failed %d\n", ret); in vpu_irq_handler()
750 vpu_to_host = vpu_cfg_readl(vpu, VPU_TO_HOST); in vpu_irq_handler()
752 vpu_ipi_handler(vpu); in vpu_irq_handler()
754 dev_err(vpu->dev, "vpu watchdog timeout! 0x%x", vpu_to_host); in vpu_irq_handler()
755 queue_work(vpu->wdt.wq, &vpu->wdt.ws); in vpu_irq_handler()
759 vpu_cfg_writel(vpu, 0x0, VPU_TO_HOST); in vpu_irq_handler()
760 clk_disable(vpu->clk); in vpu_irq_handler()
770 struct mtk_vpu *vpu; in mtk_vpu_probe() local
778 vpu = devm_kzalloc(dev, sizeof(*vpu), GFP_KERNEL); in mtk_vpu_probe()
779 if (!vpu) in mtk_vpu_probe()
782 vpu->dev = &pdev->dev; in mtk_vpu_probe()
784 vpu->reg.tcm = devm_ioremap_resource(dev, res); in mtk_vpu_probe()
785 if (IS_ERR((__force void *)vpu->reg.tcm)) in mtk_vpu_probe()
786 return PTR_ERR((__force void *)vpu->reg.tcm); in mtk_vpu_probe()
789 vpu->reg.cfg = devm_ioremap_resource(dev, res); in mtk_vpu_probe()
790 if (IS_ERR((__force void *)vpu->reg.cfg)) in mtk_vpu_probe()
791 return PTR_ERR((__force void *)vpu->reg.cfg); in mtk_vpu_probe()
794 vpu->clk = devm_clk_get(dev, "main"); in mtk_vpu_probe()
795 if (IS_ERR(vpu->clk)) { in mtk_vpu_probe()
797 return PTR_ERR(vpu->clk); in mtk_vpu_probe()
800 platform_set_drvdata(pdev, vpu); in mtk_vpu_probe()
802 ret = clk_prepare(vpu->clk); in mtk_vpu_probe()
809 vpu->wdt.wq = create_singlethread_workqueue("vpu_wdt"); in mtk_vpu_probe()
810 if (!vpu->wdt.wq) { in mtk_vpu_probe()
814 INIT_WORK(&vpu->wdt.ws, vpu_wdt_reset_func); in mtk_vpu_probe()
815 mutex_init(&vpu->vpu_mutex); in mtk_vpu_probe()
817 ret = vpu_clock_enable(vpu); in mtk_vpu_probe()
824 ret = vpu_ipi_init(vpu); in mtk_vpu_probe()
832 "vpu_init", vpu); in mtk_vpu_probe()
848 vpu_cfg_writel(vpu, 0x2, VPU_TCM_CFG); in mtk_vpu_probe()
850 vpu->enable_4GB = !!(totalram_pages() > (SZ_2G >> PAGE_SHIFT)); in mtk_vpu_probe()
851 dev_info(dev, "4GB mode %u\n", vpu->enable_4GB); in mtk_vpu_probe()
853 if (vpu->enable_4GB) { in mtk_vpu_probe()
860 ret = vpu_alloc_ext_mem(vpu, D_FW); in mtk_vpu_probe()
866 ret = vpu_alloc_ext_mem(vpu, P_FW); in mtk_vpu_probe()
872 init_waitqueue_head(&vpu->run.wq); in mtk_vpu_probe()
873 init_waitqueue_head(&vpu->ack_wq); in mtk_vpu_probe()
881 vpu->reg.irq = platform_get_irq(pdev, 0); in mtk_vpu_probe()
882 ret = devm_request_irq(dev, vpu->reg.irq, vpu_irq_handler, 0, in mtk_vpu_probe()
883 pdev->name, vpu); in mtk_vpu_probe()
889 vpu_clock_disable(vpu); in mtk_vpu_probe()
895 vpu_free_ext_mem(vpu, P_FW); in mtk_vpu_probe()
897 vpu_free_ext_mem(vpu, D_FW); in mtk_vpu_probe()
904 memset(vpu->ipi_desc, 0, sizeof(struct vpu_ipi_desc) * IPI_MAX); in mtk_vpu_probe()
906 mutex_destroy(&vpu->vpu_mutex); in mtk_vpu_probe()
908 vpu_clock_disable(vpu); in mtk_vpu_probe()
910 destroy_workqueue(vpu->wdt.wq); in mtk_vpu_probe()
925 struct mtk_vpu *vpu = platform_get_drvdata(pdev); in mtk_vpu_remove() local
930 if (vpu->wdt.wq) { in mtk_vpu_remove()
931 flush_workqueue(vpu->wdt.wq); in mtk_vpu_remove()
932 destroy_workqueue(vpu->wdt.wq); in mtk_vpu_remove()
934 vpu_free_ext_mem(vpu, P_FW); in mtk_vpu_remove()
935 vpu_free_ext_mem(vpu, D_FW); in mtk_vpu_remove()
936 mutex_destroy(&vpu->vpu_mutex); in mtk_vpu_remove()
937 clk_unprepare(vpu->clk); in mtk_vpu_remove()