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