GNU Linux-libre 4.14.266-gnu1
[releases.git] / drivers / media / platform / qcom / venus / hfi.h
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 };
78
79 /* define core states */
80 #define CORE_UNINIT                             0
81 #define CORE_INIT                               1
82
83 /* define instance states */
84 #define INST_UNINIT                             2
85 #define INST_INIT                               3
86 #define INST_LOAD_RESOURCES                     4
87 #define INST_START                              5
88 #define INST_STOP                               6
89 #define INST_RELEASE_RESOURCES                  7
90
91 struct venus_core;
92 struct venus_inst;
93
94 struct hfi_core_ops {
95         void (*event_notify)(struct venus_core *core, u32 event);
96 };
97
98 struct hfi_inst_ops {
99         void (*buf_done)(struct venus_inst *inst, unsigned int buf_type,
100                          u32 tag, u32 bytesused, u32 data_offset, u32 flags,
101                          u32 hfi_flags, u64 timestamp_us);
102         void (*event_notify)(struct venus_inst *inst, u32 event,
103                              struct hfi_event_data *data);
104 };
105
106 struct hfi_ops {
107         int (*core_init)(struct venus_core *core);
108         int (*core_deinit)(struct venus_core *core);
109         int (*core_ping)(struct venus_core *core, u32 cookie);
110         int (*core_trigger_ssr)(struct venus_core *core, u32 trigger_type);
111
112         int (*session_init)(struct venus_inst *inst, u32 session_type,
113                             u32 codec);
114         int (*session_end)(struct venus_inst *inst);
115         int (*session_abort)(struct venus_inst *inst);
116         int (*session_flush)(struct venus_inst *inst, u32 flush_mode);
117         int (*session_start)(struct venus_inst *inst);
118         int (*session_stop)(struct venus_inst *inst);
119         int (*session_continue)(struct venus_inst *inst);
120         int (*session_etb)(struct venus_inst *inst, struct hfi_frame_data *fd);
121         int (*session_ftb)(struct venus_inst *inst, struct hfi_frame_data *fd);
122         int (*session_set_buffers)(struct venus_inst *inst,
123                                    struct hfi_buffer_desc *bd);
124         int (*session_unset_buffers)(struct venus_inst *inst,
125                                      struct hfi_buffer_desc *bd);
126         int (*session_load_res)(struct venus_inst *inst);
127         int (*session_release_res)(struct venus_inst *inst);
128         int (*session_parse_seq_hdr)(struct venus_inst *inst, u32 seq_hdr,
129                                      u32 seq_hdr_len);
130         int (*session_get_seq_hdr)(struct venus_inst *inst, u32 seq_hdr,
131                                    u32 seq_hdr_len);
132         int (*session_set_property)(struct venus_inst *inst, u32 ptype,
133                                     void *pdata);
134         int (*session_get_property)(struct venus_inst *inst, u32 ptype);
135
136         int (*resume)(struct venus_core *core);
137         int (*suspend)(struct venus_core *core);
138
139         /* interrupt operations */
140         irqreturn_t (*isr)(struct venus_core *core);
141         irqreturn_t (*isr_thread)(struct venus_core *core);
142 };
143
144 int hfi_create(struct venus_core *core, const struct hfi_core_ops *ops);
145 void hfi_destroy(struct venus_core *core);
146
147 int hfi_core_init(struct venus_core *core);
148 int hfi_core_deinit(struct venus_core *core, bool blocking);
149 int hfi_core_suspend(struct venus_core *core);
150 int hfi_core_resume(struct venus_core *core, bool force);
151 int hfi_core_trigger_ssr(struct venus_core *core, u32 type);
152 int hfi_core_ping(struct venus_core *core);
153 int hfi_session_create(struct venus_inst *inst, const struct hfi_inst_ops *ops);
154 void hfi_session_destroy(struct venus_inst *inst);
155 int hfi_session_init(struct venus_inst *inst, u32 pixfmt);
156 int hfi_session_deinit(struct venus_inst *inst);
157 int hfi_session_start(struct venus_inst *inst);
158 int hfi_session_stop(struct venus_inst *inst);
159 int hfi_session_continue(struct venus_inst *inst);
160 int hfi_session_abort(struct venus_inst *inst);
161 int hfi_session_load_res(struct venus_inst *inst);
162 int hfi_session_unload_res(struct venus_inst *inst);
163 int hfi_session_flush(struct venus_inst *inst);
164 int hfi_session_set_buffers(struct venus_inst *inst,
165                             struct hfi_buffer_desc *bd);
166 int hfi_session_unset_buffers(struct venus_inst *inst,
167                               struct hfi_buffer_desc *bd);
168 int hfi_session_get_property(struct venus_inst *inst, u32 ptype,
169                              union hfi_get_property *hprop);
170 int hfi_session_set_property(struct venus_inst *inst, u32 ptype, void *pdata);
171 int hfi_session_process_buf(struct venus_inst *inst, struct hfi_frame_data *f);
172 irqreturn_t hfi_isr_thread(int irq, void *dev_id);
173 irqreturn_t hfi_isr(int irq, void *dev);
174
175 #endif