linux/drivers/media/platform/mtk-mdp/mtk_mdp_vpu.c
<<
>>
Prefs
   1/*
   2 * Copyright (c) 2015-2016 MediaTek Inc.
   3 * Author: Houlong Wei <houlong.wei@mediatek.com>
   4 *         Ming Hsiu Tsai <minghsiu.tsai@mediatek.com>
   5 *
   6 * This program is free software; you can redistribute it and/or modify
   7 * it under the terms of the GNU General Public License version 2 as
   8 * published by the Free Software Foundation.
   9 *
  10 * This program is distributed in the hope that it will be useful,
  11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13 * GNU General Public License for more details.
  14 */
  15
  16#include "mtk_mdp_core.h"
  17#include "mtk_mdp_vpu.h"
  18#include "mtk_vpu.h"
  19
  20
  21static inline struct mtk_mdp_ctx *vpu_to_ctx(struct mtk_mdp_vpu *vpu)
  22{
  23        return container_of(vpu, struct mtk_mdp_ctx, vpu);
  24}
  25
  26static void mtk_mdp_vpu_handle_init_ack(struct mdp_ipi_comm_ack *msg)
  27{
  28        struct mtk_mdp_vpu *vpu = (struct mtk_mdp_vpu *)
  29                                        (unsigned long)msg->ap_inst;
  30
  31        /* mapping VPU address to kernel virtual address */
  32        vpu->vsi = (struct mdp_process_vsi *)
  33                        vpu_mapping_dm_addr(vpu->pdev, msg->vpu_inst_addr);
  34        vpu->inst_addr = msg->vpu_inst_addr;
  35}
  36
  37static void mtk_mdp_vpu_ipi_handler(void *data, unsigned int len, void *priv)
  38{
  39        unsigned int msg_id = *(unsigned int *)data;
  40        struct mdp_ipi_comm_ack *msg = (struct mdp_ipi_comm_ack *)data;
  41        struct mtk_mdp_vpu *vpu = (struct mtk_mdp_vpu *)
  42                                        (unsigned long)msg->ap_inst;
  43        struct mtk_mdp_ctx *ctx;
  44
  45        vpu->failure = msg->status;
  46        if (!vpu->failure) {
  47                switch (msg_id) {
  48                case VPU_MDP_INIT_ACK:
  49                        mtk_mdp_vpu_handle_init_ack(data);
  50                        break;
  51                case VPU_MDP_DEINIT_ACK:
  52                case VPU_MDP_PROCESS_ACK:
  53                        break;
  54                default:
  55                        ctx = vpu_to_ctx(vpu);
  56                        dev_err(&ctx->mdp_dev->pdev->dev,
  57                                "handle unknown ipi msg:0x%x\n",
  58                                msg_id);
  59                        break;
  60                }
  61        } else {
  62                ctx = vpu_to_ctx(vpu);
  63                mtk_mdp_dbg(0, "[%d]:msg 0x%x, failure:%d", ctx->id,
  64                            msg_id, vpu->failure);
  65        }
  66}
  67
  68int mtk_mdp_vpu_register(struct platform_device *pdev)
  69{
  70        struct mtk_mdp_dev *mdp = platform_get_drvdata(pdev);
  71        int err;
  72
  73        err = vpu_ipi_register(mdp->vpu_dev, IPI_MDP,
  74                               mtk_mdp_vpu_ipi_handler, "mdp_vpu", NULL);
  75        if (err)
  76                dev_err(&mdp->pdev->dev,
  77                        "vpu_ipi_registration fail status=%d\n", err);
  78
  79        return err;
  80}
  81
  82static int mtk_mdp_vpu_send_msg(void *msg, int len, struct mtk_mdp_vpu *vpu,
  83                                int id)
  84{
  85        struct mtk_mdp_ctx *ctx = vpu_to_ctx(vpu);
  86        int err;
  87
  88        if (!vpu->pdev) {
  89                mtk_mdp_dbg(1, "[%d]:vpu pdev is NULL", ctx->id);
  90                return -EINVAL;
  91        }
  92
  93        mutex_lock(&ctx->mdp_dev->vpulock);
  94        err = vpu_ipi_send(vpu->pdev, (enum ipi_id)id, msg, len);
  95        if (err)
  96                dev_err(&ctx->mdp_dev->pdev->dev,
  97                        "vpu_ipi_send fail status %d\n", err);
  98        mutex_unlock(&ctx->mdp_dev->vpulock);
  99
 100        return err;
 101}
 102
 103static int mtk_mdp_vpu_send_ap_ipi(struct mtk_mdp_vpu *vpu, uint32_t msg_id)
 104{
 105        int err;
 106        struct mdp_ipi_comm msg;
 107
 108        msg.msg_id = msg_id;
 109        msg.ipi_id = IPI_MDP;
 110        msg.vpu_inst_addr = vpu->inst_addr;
 111        msg.ap_inst = (unsigned long)vpu;
 112        err = mtk_mdp_vpu_send_msg((void *)&msg, sizeof(msg), vpu, IPI_MDP);
 113        if (!err && vpu->failure)
 114                err = -EINVAL;
 115
 116        return err;
 117}
 118
 119int mtk_mdp_vpu_init(struct mtk_mdp_vpu *vpu)
 120{
 121        int err;
 122        struct mdp_ipi_init msg;
 123        struct mtk_mdp_ctx *ctx = vpu_to_ctx(vpu);
 124
 125        vpu->pdev = ctx->mdp_dev->vpu_dev;
 126
 127        msg.msg_id = AP_MDP_INIT;
 128        msg.ipi_id = IPI_MDP;
 129        msg.ap_inst = (unsigned long)vpu;
 130        err = mtk_mdp_vpu_send_msg((void *)&msg, sizeof(msg), vpu, IPI_MDP);
 131        if (!err && vpu->failure)
 132                err = -EINVAL;
 133
 134        return err;
 135}
 136
 137int mtk_mdp_vpu_deinit(struct mtk_mdp_vpu *vpu)
 138{
 139        return mtk_mdp_vpu_send_ap_ipi(vpu, AP_MDP_DEINIT);
 140}
 141
 142int mtk_mdp_vpu_process(struct mtk_mdp_vpu *vpu)
 143{
 144        return mtk_mdp_vpu_send_ap_ipi(vpu, AP_MDP_PROCESS);
 145}
 146