1/* SPDX-License-Identifier: GPL-2.0-only */
2/*
3 * Copyright (c) 2012-2016, The Linux Foundation. All rights reserved.
4 * Copyright (C) 2017 Linaro Ltd.
5 */
6#ifndef __HFI_H__
7#define __HFI_H__
8
9#include <linux/interrupt.h>
10
11#include "hfi_helper.h"
12
13#define VIDC_SESSION_TYPE_VPE			0
14#define VIDC_SESSION_TYPE_ENC			1
15#define VIDC_SESSION_TYPE_DEC			2
16
17#define VIDC_RESOURCE_NONE			0
18#define VIDC_RESOURCE_OCMEM			1
19#define VIDC_RESOURCE_VMEM			2
20
21struct hfi_buffer_desc {
22	u32 buffer_type;
23	u32 buffer_size;
24	u32 num_buffers;
25	u32 device_addr;
26	u32 extradata_addr;
27	u32 extradata_size;
28	u32 response_required;
29};
30
31struct hfi_frame_data {
32	u32 buffer_type;
33	u32 device_addr;
34	u32 extradata_addr;
35	u64 timestamp;
36	u32 flags;
37	u32 offset;
38	u32 alloc_len;
39	u32 filled_len;
40	u32 mark_target;
41	u32 mark_data;
42	u32 clnt_data;
43	u32 extradata_size;
44};
45
46union hfi_get_property {
47	struct hfi_profile_level profile_level;
48	struct hfi_buffer_requirements bufreq[HFI_BUFFER_TYPE_MAX];
49};
50
51/* HFI events */
52#define EVT_SYS_EVENT_CHANGE			1
53#define EVT_SYS_WATCHDOG_TIMEOUT		2
54#define EVT_SYS_ERROR				3
55#define EVT_SESSION_ERROR			4
56
57/* HFI event callback structure */
58struct hfi_event_data {
59	u32 error;
60	u32 height;
61	u32 width;
62	u32 event_type;
63	u32 packet_buffer;
64	u32 extradata_buffer;
65	u32 tag;
66	u32 profile;
67	u32 level;
68	/* the following properties start appear from v4 onwards */
69	u32 bit_depth;
70	u32 pic_struct;
71	u32 colour_space;
72	u32 entropy_mode;
73	u32 buf_count;
74	struct {
75		u32 left, top;
76		u32 width, height;
77	} input_crop;
78};
79
80/* define core states */
81#define CORE_UNINIT				0
82#define CORE_INIT				1
83
84/* define instance states */
85#define INST_UNINIT				2
86#define INST_INIT				3
87#define INST_LOAD_RESOURCES			4
88#define INST_START				5
89#define INST_STOP				6
90#define INST_RELEASE_RESOURCES			7
91
92struct venus_core;
93struct venus_inst;
94
95struct hfi_core_ops {
96	void (*event_notify)(struct venus_core *core, u32 event);
97};
98
99struct hfi_inst_ops {
100	void (*buf_done)(struct venus_inst *inst, unsigned int buf_type,
101			 u32 tag, u32 bytesused, u32 data_offset, u32 flags,
102			 u32 hfi_flags, u64 timestamp_us);
103	void (*event_notify)(struct venus_inst *inst, u32 event,
104			     struct hfi_event_data *data);
105	void (*flush_done)(struct venus_inst *inst);
106};
107
108struct hfi_ops {
109	int (*core_init)(struct venus_core *core);
110	int (*core_deinit)(struct venus_core *core);
111	int (*core_ping)(struct venus_core *core, u32 cookie);
112	int (*core_trigger_ssr)(struct venus_core *core, u32 trigger_type);
113
114	int (*session_init)(struct venus_inst *inst, u32 session_type,
115			    u32 codec);
116	int (*session_end)(struct venus_inst *inst);
117	int (*session_abort)(struct venus_inst *inst);
118	int (*session_flush)(struct venus_inst *inst, u32 flush_mode);
119	int (*session_start)(struct venus_inst *inst);
120	int (*session_stop)(struct venus_inst *inst);
121	int (*session_continue)(struct venus_inst *inst);
122	int (*session_etb)(struct venus_inst *inst, struct hfi_frame_data *fd);
123	int (*session_ftb)(struct venus_inst *inst, struct hfi_frame_data *fd);
124	int (*session_set_buffers)(struct venus_inst *inst,
125				   struct hfi_buffer_desc *bd);
126	int (*session_unset_buffers)(struct venus_inst *inst,
127				     struct hfi_buffer_desc *bd);
128	int (*session_load_res)(struct venus_inst *inst);
129	int (*session_release_res)(struct venus_inst *inst);
130	int (*session_parse_seq_hdr)(struct venus_inst *inst, u32 seq_hdr,
131				     u32 seq_hdr_len);
132	int (*session_get_seq_hdr)(struct venus_inst *inst, u32 seq_hdr,
133				   u32 seq_hdr_len);
134	int (*session_set_property)(struct venus_inst *inst, u32 ptype,
135				    void *pdata);
136	int (*session_get_property)(struct venus_inst *inst, u32 ptype);
137
138	int (*resume)(struct venus_core *core);
139	int (*suspend)(struct venus_core *core);
140
141	/* interrupt operations */
142	irqreturn_t (*isr)(struct venus_core *core);
143	irqreturn_t (*isr_thread)(struct venus_core *core);
144};
145
146int hfi_create(struct venus_core *core, const struct hfi_core_ops *ops);
147void hfi_destroy(struct venus_core *core);
148void hfi_reinit(struct venus_core *core);
149
150int hfi_core_init(struct venus_core *core);
151int hfi_core_deinit(struct venus_core *core, bool blocking);
152int hfi_core_suspend(struct venus_core *core);
153int hfi_core_resume(struct venus_core *core, bool force);
154int hfi_core_trigger_ssr(struct venus_core *core, u32 type);
155int hfi_core_ping(struct venus_core *core);
156int hfi_session_create(struct venus_inst *inst, const struct hfi_inst_ops *ops);
157void hfi_session_destroy(struct venus_inst *inst);
158int hfi_session_init(struct venus_inst *inst, u32 pixfmt);
159int hfi_session_deinit(struct venus_inst *inst);
160int hfi_session_start(struct venus_inst *inst);
161int hfi_session_stop(struct venus_inst *inst);
162int hfi_session_continue(struct venus_inst *inst);
163int hfi_session_abort(struct venus_inst *inst);
164int hfi_session_load_res(struct venus_inst *inst);
165int hfi_session_unload_res(struct venus_inst *inst);
166int hfi_session_flush(struct venus_inst *inst, u32 type, bool block);
167int hfi_session_set_buffers(struct venus_inst *inst,
168			    struct hfi_buffer_desc *bd);
169int hfi_session_unset_buffers(struct venus_inst *inst,
170			      struct hfi_buffer_desc *bd);
171int hfi_session_get_property(struct venus_inst *inst, u32 ptype,
172			     union hfi_get_property *hprop);
173int hfi_session_set_property(struct venus_inst *inst, u32 ptype, void *pdata);
174int hfi_session_process_buf(struct venus_inst *inst, struct hfi_frame_data *f);
175irqreturn_t hfi_isr_thread(int irq, void *dev_id);
176irqreturn_t hfi_isr(int irq, void *dev);
177
178#endif
179