1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (c) 2015-2016 MediaTek Inc.
4 * Author: Houlong Wei <houlong.wei@mediatek.com>
5 * Ming Hsiu Tsai <minghsiu.tsai@mediatek.com>
8 #include "mtk_mdp_core.h"
9 #include "mtk_mdp_vpu.h"
13 static inline struct mtk_mdp_ctx
*vpu_to_ctx(struct mtk_mdp_vpu
*vpu
)
15 return container_of(vpu
, struct mtk_mdp_ctx
, vpu
);
18 static void mtk_mdp_vpu_handle_init_ack(struct mdp_ipi_comm_ack
*msg
)
20 struct mtk_mdp_vpu
*vpu
= (struct mtk_mdp_vpu
*)
21 (unsigned long)msg
->ap_inst
;
23 /* mapping VPU address to kernel virtual address */
24 vpu
->vsi
= (struct mdp_process_vsi
*)
25 vpu_mapping_dm_addr(vpu
->pdev
, msg
->vpu_inst_addr
);
26 vpu
->inst_addr
= msg
->vpu_inst_addr
;
29 static void mtk_mdp_vpu_ipi_handler(void *data
, unsigned int len
, void *priv
)
31 unsigned int msg_id
= *(unsigned int *)data
;
32 struct mdp_ipi_comm_ack
*msg
= (struct mdp_ipi_comm_ack
*)data
;
33 struct mtk_mdp_vpu
*vpu
= (struct mtk_mdp_vpu
*)
34 (unsigned long)msg
->ap_inst
;
35 struct mtk_mdp_ctx
*ctx
;
37 vpu
->failure
= msg
->status
;
40 case VPU_MDP_INIT_ACK
:
41 mtk_mdp_vpu_handle_init_ack(data
);
43 case VPU_MDP_DEINIT_ACK
:
44 case VPU_MDP_PROCESS_ACK
:
47 ctx
= vpu_to_ctx(vpu
);
48 dev_err(&ctx
->mdp_dev
->pdev
->dev
,
49 "handle unknown ipi msg:0x%x\n",
54 ctx
= vpu_to_ctx(vpu
);
55 mtk_mdp_dbg(0, "[%d]:msg 0x%x, failure:%d", ctx
->id
,
56 msg_id
, vpu
->failure
);
60 int mtk_mdp_vpu_register(struct platform_device
*pdev
)
62 struct mtk_mdp_dev
*mdp
= platform_get_drvdata(pdev
);
65 err
= vpu_ipi_register(mdp
->vpu_dev
, IPI_MDP
,
66 mtk_mdp_vpu_ipi_handler
, "mdp_vpu", NULL
);
68 dev_err(&mdp
->pdev
->dev
,
69 "vpu_ipi_registration fail status=%d\n", err
);
74 static int mtk_mdp_vpu_send_msg(void *msg
, int len
, struct mtk_mdp_vpu
*vpu
,
77 struct mtk_mdp_ctx
*ctx
= vpu_to_ctx(vpu
);
81 mtk_mdp_dbg(1, "[%d]:vpu pdev is NULL", ctx
->id
);
85 mutex_lock(&ctx
->mdp_dev
->vpulock
);
86 err
= vpu_ipi_send(vpu
->pdev
, (enum ipi_id
)id
, msg
, len
);
88 dev_err(&ctx
->mdp_dev
->pdev
->dev
,
89 "vpu_ipi_send fail status %d\n", err
);
90 mutex_unlock(&ctx
->mdp_dev
->vpulock
);
95 static int mtk_mdp_vpu_send_ap_ipi(struct mtk_mdp_vpu
*vpu
, uint32_t msg_id
)
98 struct mdp_ipi_comm msg
;
101 msg
.ipi_id
= IPI_MDP
;
102 msg
.vpu_inst_addr
= vpu
->inst_addr
;
103 msg
.ap_inst
= (unsigned long)vpu
;
104 err
= mtk_mdp_vpu_send_msg((void *)&msg
, sizeof(msg
), vpu
, IPI_MDP
);
105 if (!err
&& vpu
->failure
)
111 int mtk_mdp_vpu_init(struct mtk_mdp_vpu
*vpu
)
114 struct mdp_ipi_init msg
;
115 struct mtk_mdp_ctx
*ctx
= vpu_to_ctx(vpu
);
117 vpu
->pdev
= ctx
->mdp_dev
->vpu_dev
;
119 msg
.msg_id
= AP_MDP_INIT
;
120 msg
.ipi_id
= IPI_MDP
;
121 msg
.ap_inst
= (unsigned long)vpu
;
122 err
= mtk_mdp_vpu_send_msg((void *)&msg
, sizeof(msg
), vpu
, IPI_MDP
);
123 if (!err
&& vpu
->failure
)
129 int mtk_mdp_vpu_deinit(struct mtk_mdp_vpu
*vpu
)
131 return mtk_mdp_vpu_send_ap_ipi(vpu
, AP_MDP_DEINIT
);
134 int mtk_mdp_vpu_process(struct mtk_mdp_vpu
*vpu
)
136 return mtk_mdp_vpu_send_ap_ipi(vpu
, AP_MDP_PROCESS
);