18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Copyright (c) 2012-2016, The Linux Foundation. All rights reserved.
48c2ecf20Sopenharmony_ci * Copyright (C) 2017 Linaro Ltd.
58c2ecf20Sopenharmony_ci */
68c2ecf20Sopenharmony_ci#ifndef __HFI_H__
78c2ecf20Sopenharmony_ci#define __HFI_H__
88c2ecf20Sopenharmony_ci
98c2ecf20Sopenharmony_ci#include <linux/interrupt.h>
108c2ecf20Sopenharmony_ci
118c2ecf20Sopenharmony_ci#include "hfi_helper.h"
128c2ecf20Sopenharmony_ci
138c2ecf20Sopenharmony_ci#define VIDC_SESSION_TYPE_VPE			0
148c2ecf20Sopenharmony_ci#define VIDC_SESSION_TYPE_ENC			1
158c2ecf20Sopenharmony_ci#define VIDC_SESSION_TYPE_DEC			2
168c2ecf20Sopenharmony_ci
178c2ecf20Sopenharmony_ci#define VIDC_RESOURCE_NONE			0
188c2ecf20Sopenharmony_ci#define VIDC_RESOURCE_OCMEM			1
198c2ecf20Sopenharmony_ci#define VIDC_RESOURCE_VMEM			2
208c2ecf20Sopenharmony_ci
218c2ecf20Sopenharmony_cistruct hfi_buffer_desc {
228c2ecf20Sopenharmony_ci	u32 buffer_type;
238c2ecf20Sopenharmony_ci	u32 buffer_size;
248c2ecf20Sopenharmony_ci	u32 num_buffers;
258c2ecf20Sopenharmony_ci	u32 device_addr;
268c2ecf20Sopenharmony_ci	u32 extradata_addr;
278c2ecf20Sopenharmony_ci	u32 extradata_size;
288c2ecf20Sopenharmony_ci	u32 response_required;
298c2ecf20Sopenharmony_ci};
308c2ecf20Sopenharmony_ci
318c2ecf20Sopenharmony_cistruct hfi_frame_data {
328c2ecf20Sopenharmony_ci	u32 buffer_type;
338c2ecf20Sopenharmony_ci	u32 device_addr;
348c2ecf20Sopenharmony_ci	u32 extradata_addr;
358c2ecf20Sopenharmony_ci	u64 timestamp;
368c2ecf20Sopenharmony_ci	u32 flags;
378c2ecf20Sopenharmony_ci	u32 offset;
388c2ecf20Sopenharmony_ci	u32 alloc_len;
398c2ecf20Sopenharmony_ci	u32 filled_len;
408c2ecf20Sopenharmony_ci	u32 mark_target;
418c2ecf20Sopenharmony_ci	u32 mark_data;
428c2ecf20Sopenharmony_ci	u32 clnt_data;
438c2ecf20Sopenharmony_ci	u32 extradata_size;
448c2ecf20Sopenharmony_ci};
458c2ecf20Sopenharmony_ci
468c2ecf20Sopenharmony_ciunion hfi_get_property {
478c2ecf20Sopenharmony_ci	struct hfi_profile_level profile_level;
488c2ecf20Sopenharmony_ci	struct hfi_buffer_requirements bufreq[HFI_BUFFER_TYPE_MAX];
498c2ecf20Sopenharmony_ci};
508c2ecf20Sopenharmony_ci
518c2ecf20Sopenharmony_ci/* HFI events */
528c2ecf20Sopenharmony_ci#define EVT_SYS_EVENT_CHANGE			1
538c2ecf20Sopenharmony_ci#define EVT_SYS_WATCHDOG_TIMEOUT		2
548c2ecf20Sopenharmony_ci#define EVT_SYS_ERROR				3
558c2ecf20Sopenharmony_ci#define EVT_SESSION_ERROR			4
568c2ecf20Sopenharmony_ci
578c2ecf20Sopenharmony_ci/* HFI event callback structure */
588c2ecf20Sopenharmony_cistruct hfi_event_data {
598c2ecf20Sopenharmony_ci	u32 error;
608c2ecf20Sopenharmony_ci	u32 height;
618c2ecf20Sopenharmony_ci	u32 width;
628c2ecf20Sopenharmony_ci	u32 event_type;
638c2ecf20Sopenharmony_ci	u32 packet_buffer;
648c2ecf20Sopenharmony_ci	u32 extradata_buffer;
658c2ecf20Sopenharmony_ci	u32 tag;
668c2ecf20Sopenharmony_ci	u32 profile;
678c2ecf20Sopenharmony_ci	u32 level;
688c2ecf20Sopenharmony_ci	/* the following properties start appear from v4 onwards */
698c2ecf20Sopenharmony_ci	u32 bit_depth;
708c2ecf20Sopenharmony_ci	u32 pic_struct;
718c2ecf20Sopenharmony_ci	u32 colour_space;
728c2ecf20Sopenharmony_ci	u32 entropy_mode;
738c2ecf20Sopenharmony_ci	u32 buf_count;
748c2ecf20Sopenharmony_ci	struct {
758c2ecf20Sopenharmony_ci		u32 left, top;
768c2ecf20Sopenharmony_ci		u32 width, height;
778c2ecf20Sopenharmony_ci	} input_crop;
788c2ecf20Sopenharmony_ci};
798c2ecf20Sopenharmony_ci
808c2ecf20Sopenharmony_ci/* define core states */
818c2ecf20Sopenharmony_ci#define CORE_UNINIT				0
828c2ecf20Sopenharmony_ci#define CORE_INIT				1
838c2ecf20Sopenharmony_ci
848c2ecf20Sopenharmony_ci/* define instance states */
858c2ecf20Sopenharmony_ci#define INST_UNINIT				2
868c2ecf20Sopenharmony_ci#define INST_INIT				3
878c2ecf20Sopenharmony_ci#define INST_LOAD_RESOURCES			4
888c2ecf20Sopenharmony_ci#define INST_START				5
898c2ecf20Sopenharmony_ci#define INST_STOP				6
908c2ecf20Sopenharmony_ci#define INST_RELEASE_RESOURCES			7
918c2ecf20Sopenharmony_ci
928c2ecf20Sopenharmony_cistruct venus_core;
938c2ecf20Sopenharmony_cistruct venus_inst;
948c2ecf20Sopenharmony_ci
958c2ecf20Sopenharmony_cistruct hfi_core_ops {
968c2ecf20Sopenharmony_ci	void (*event_notify)(struct venus_core *core, u32 event);
978c2ecf20Sopenharmony_ci};
988c2ecf20Sopenharmony_ci
998c2ecf20Sopenharmony_cistruct hfi_inst_ops {
1008c2ecf20Sopenharmony_ci	void (*buf_done)(struct venus_inst *inst, unsigned int buf_type,
1018c2ecf20Sopenharmony_ci			 u32 tag, u32 bytesused, u32 data_offset, u32 flags,
1028c2ecf20Sopenharmony_ci			 u32 hfi_flags, u64 timestamp_us);
1038c2ecf20Sopenharmony_ci	void (*event_notify)(struct venus_inst *inst, u32 event,
1048c2ecf20Sopenharmony_ci			     struct hfi_event_data *data);
1058c2ecf20Sopenharmony_ci	void (*flush_done)(struct venus_inst *inst);
1068c2ecf20Sopenharmony_ci};
1078c2ecf20Sopenharmony_ci
1088c2ecf20Sopenharmony_cistruct hfi_ops {
1098c2ecf20Sopenharmony_ci	int (*core_init)(struct venus_core *core);
1108c2ecf20Sopenharmony_ci	int (*core_deinit)(struct venus_core *core);
1118c2ecf20Sopenharmony_ci	int (*core_ping)(struct venus_core *core, u32 cookie);
1128c2ecf20Sopenharmony_ci	int (*core_trigger_ssr)(struct venus_core *core, u32 trigger_type);
1138c2ecf20Sopenharmony_ci
1148c2ecf20Sopenharmony_ci	int (*session_init)(struct venus_inst *inst, u32 session_type,
1158c2ecf20Sopenharmony_ci			    u32 codec);
1168c2ecf20Sopenharmony_ci	int (*session_end)(struct venus_inst *inst);
1178c2ecf20Sopenharmony_ci	int (*session_abort)(struct venus_inst *inst);
1188c2ecf20Sopenharmony_ci	int (*session_flush)(struct venus_inst *inst, u32 flush_mode);
1198c2ecf20Sopenharmony_ci	int (*session_start)(struct venus_inst *inst);
1208c2ecf20Sopenharmony_ci	int (*session_stop)(struct venus_inst *inst);
1218c2ecf20Sopenharmony_ci	int (*session_continue)(struct venus_inst *inst);
1228c2ecf20Sopenharmony_ci	int (*session_etb)(struct venus_inst *inst, struct hfi_frame_data *fd);
1238c2ecf20Sopenharmony_ci	int (*session_ftb)(struct venus_inst *inst, struct hfi_frame_data *fd);
1248c2ecf20Sopenharmony_ci	int (*session_set_buffers)(struct venus_inst *inst,
1258c2ecf20Sopenharmony_ci				   struct hfi_buffer_desc *bd);
1268c2ecf20Sopenharmony_ci	int (*session_unset_buffers)(struct venus_inst *inst,
1278c2ecf20Sopenharmony_ci				     struct hfi_buffer_desc *bd);
1288c2ecf20Sopenharmony_ci	int (*session_load_res)(struct venus_inst *inst);
1298c2ecf20Sopenharmony_ci	int (*session_release_res)(struct venus_inst *inst);
1308c2ecf20Sopenharmony_ci	int (*session_parse_seq_hdr)(struct venus_inst *inst, u32 seq_hdr,
1318c2ecf20Sopenharmony_ci				     u32 seq_hdr_len);
1328c2ecf20Sopenharmony_ci	int (*session_get_seq_hdr)(struct venus_inst *inst, u32 seq_hdr,
1338c2ecf20Sopenharmony_ci				   u32 seq_hdr_len);
1348c2ecf20Sopenharmony_ci	int (*session_set_property)(struct venus_inst *inst, u32 ptype,
1358c2ecf20Sopenharmony_ci				    void *pdata);
1368c2ecf20Sopenharmony_ci	int (*session_get_property)(struct venus_inst *inst, u32 ptype);
1378c2ecf20Sopenharmony_ci
1388c2ecf20Sopenharmony_ci	int (*resume)(struct venus_core *core);
1398c2ecf20Sopenharmony_ci	int (*suspend)(struct venus_core *core);
1408c2ecf20Sopenharmony_ci
1418c2ecf20Sopenharmony_ci	/* interrupt operations */
1428c2ecf20Sopenharmony_ci	irqreturn_t (*isr)(struct venus_core *core);
1438c2ecf20Sopenharmony_ci	irqreturn_t (*isr_thread)(struct venus_core *core);
1448c2ecf20Sopenharmony_ci};
1458c2ecf20Sopenharmony_ci
1468c2ecf20Sopenharmony_ciint hfi_create(struct venus_core *core, const struct hfi_core_ops *ops);
1478c2ecf20Sopenharmony_civoid hfi_destroy(struct venus_core *core);
1488c2ecf20Sopenharmony_civoid hfi_reinit(struct venus_core *core);
1498c2ecf20Sopenharmony_ci
1508c2ecf20Sopenharmony_ciint hfi_core_init(struct venus_core *core);
1518c2ecf20Sopenharmony_ciint hfi_core_deinit(struct venus_core *core, bool blocking);
1528c2ecf20Sopenharmony_ciint hfi_core_suspend(struct venus_core *core);
1538c2ecf20Sopenharmony_ciint hfi_core_resume(struct venus_core *core, bool force);
1548c2ecf20Sopenharmony_ciint hfi_core_trigger_ssr(struct venus_core *core, u32 type);
1558c2ecf20Sopenharmony_ciint hfi_core_ping(struct venus_core *core);
1568c2ecf20Sopenharmony_ciint hfi_session_create(struct venus_inst *inst, const struct hfi_inst_ops *ops);
1578c2ecf20Sopenharmony_civoid hfi_session_destroy(struct venus_inst *inst);
1588c2ecf20Sopenharmony_ciint hfi_session_init(struct venus_inst *inst, u32 pixfmt);
1598c2ecf20Sopenharmony_ciint hfi_session_deinit(struct venus_inst *inst);
1608c2ecf20Sopenharmony_ciint hfi_session_start(struct venus_inst *inst);
1618c2ecf20Sopenharmony_ciint hfi_session_stop(struct venus_inst *inst);
1628c2ecf20Sopenharmony_ciint hfi_session_continue(struct venus_inst *inst);
1638c2ecf20Sopenharmony_ciint hfi_session_abort(struct venus_inst *inst);
1648c2ecf20Sopenharmony_ciint hfi_session_load_res(struct venus_inst *inst);
1658c2ecf20Sopenharmony_ciint hfi_session_unload_res(struct venus_inst *inst);
1668c2ecf20Sopenharmony_ciint hfi_session_flush(struct venus_inst *inst, u32 type, bool block);
1678c2ecf20Sopenharmony_ciint hfi_session_set_buffers(struct venus_inst *inst,
1688c2ecf20Sopenharmony_ci			    struct hfi_buffer_desc *bd);
1698c2ecf20Sopenharmony_ciint hfi_session_unset_buffers(struct venus_inst *inst,
1708c2ecf20Sopenharmony_ci			      struct hfi_buffer_desc *bd);
1718c2ecf20Sopenharmony_ciint hfi_session_get_property(struct venus_inst *inst, u32 ptype,
1728c2ecf20Sopenharmony_ci			     union hfi_get_property *hprop);
1738c2ecf20Sopenharmony_ciint hfi_session_set_property(struct venus_inst *inst, u32 ptype, void *pdata);
1748c2ecf20Sopenharmony_ciint hfi_session_process_buf(struct venus_inst *inst, struct hfi_frame_data *f);
1758c2ecf20Sopenharmony_ciirqreturn_t hfi_isr_thread(int irq, void *dev_id);
1768c2ecf20Sopenharmony_ciirqreturn_t hfi_isr(int irq, void *dev);
1778c2ecf20Sopenharmony_ci
1788c2ecf20Sopenharmony_ci#endif
179