blob: 925918c42b6ab6762f0689f377efdaef1bd662e0 [file] [log] [blame]
Praneeth Paladugu6e6fbdb2017-01-16 15:43:01 -08001/* Copyright (c) 2012-2017, The Linux Foundation. All rights reserved.
2 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License version 2 and
5 * only version 2 as published by the Free Software Foundation.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 */
13
14#ifndef __H_VENUS_HFI_H__
15#define __H_VENUS_HFI_H__
16
17#include <linux/clk.h>
18#include <linux/mutex.h>
19#include <linux/platform_device.h>
20#include <linux/pm_qos.h>
21#include <linux/spinlock.h>
Praneeth Paladugu6e6fbdb2017-01-16 15:43:01 -080022#include "vidc_hfi_api.h"
23#include "vidc_hfi_helper.h"
24#include "vidc_hfi_api.h"
25#include "vidc_hfi.h"
26#include "msm_vidc_resources.h"
27#include "hfi_packetization.h"
28
29#define HFI_MASK_QHDR_TX_TYPE 0xFF000000
30#define HFI_MASK_QHDR_RX_TYPE 0x00FF0000
31#define HFI_MASK_QHDR_PRI_TYPE 0x0000FF00
32#define HFI_MASK_QHDR_Q_ID_TYPE 0x000000FF
33#define HFI_Q_ID_HOST_TO_CTRL_CMD_Q 0x00
34#define HFI_Q_ID_CTRL_TO_HOST_MSG_Q 0x01
35#define HFI_Q_ID_CTRL_TO_HOST_DEBUG_Q 0x02
36#define HFI_MASK_QHDR_STATUS 0x000000FF
37
38#define VIDC_MAX_UNCOMPRESSED_FMT_PLANES 3
39
40#define VIDC_IFACEQ_NUMQ 3
41#define VIDC_IFACEQ_CMDQ_IDX 0
42#define VIDC_IFACEQ_MSGQ_IDX 1
43#define VIDC_IFACEQ_DBGQ_IDX 2
44#define VIDC_IFACEQ_MAX_BUF_COUNT 50
45#define VIDC_IFACE_MAX_PARALLEL_CLNTS 16
46#define VIDC_IFACEQ_DFLT_QHDR 0x01010000
47
48#define VIDC_MAX_NAME_LENGTH 64
49#define VIDC_MAX_PC_SKIP_COUNT 10
Shivendra Kakraniac1f60e02017-04-13 00:07:26 -070050#define VIDC_MAX_SUBCACHES 4
51#define VIDC_MAX_SUBCACHE_SIZE 52
52
Praneeth Paladugu6e6fbdb2017-01-16 15:43:01 -080053struct hfi_queue_table_header {
54 u32 qtbl_version;
55 u32 qtbl_size;
56 u32 qtbl_qhdr0_offset;
57 u32 qtbl_qhdr_size;
58 u32 qtbl_num_q;
59 u32 qtbl_num_active_q;
60 void *device_addr;
61 char name[256];
62};
63
64struct hfi_queue_header {
65 u32 qhdr_status;
66 u32 qhdr_start_addr;
67 u32 qhdr_type;
68 u32 qhdr_q_size;
69 u32 qhdr_pkt_size;
70 u32 qhdr_pkt_drop_cnt;
71 u32 qhdr_rx_wm;
72 u32 qhdr_tx_wm;
73 u32 qhdr_rx_req;
74 u32 qhdr_tx_req;
75 u32 qhdr_rx_irq_status;
76 u32 qhdr_tx_irq_status;
77 u32 qhdr_read_idx;
78 u32 qhdr_write_idx;
79};
80
81struct hfi_mem_map_table {
82 u32 mem_map_num_entries;
83 u32 mem_map_table_base_addr;
84};
85
86struct hfi_mem_map {
87 u32 virtual_addr;
88 u32 physical_addr;
89 u32 size;
90 u32 attr;
91};
92
93#define VIDC_IFACEQ_TABLE_SIZE (sizeof(struct hfi_queue_table_header) \
94 + sizeof(struct hfi_queue_header) * VIDC_IFACEQ_NUMQ)
95
96#define VIDC_IFACEQ_QUEUE_SIZE (VIDC_IFACEQ_MAX_PKT_SIZE * \
97 VIDC_IFACEQ_MAX_BUF_COUNT * VIDC_IFACE_MAX_PARALLEL_CLNTS)
98
99#define VIDC_IFACEQ_GET_QHDR_START_ADDR(ptr, i) \
100 (void *)((ptr + sizeof(struct hfi_queue_table_header)) + \
101 (i * sizeof(struct hfi_queue_header)))
102
103#define QDSS_SIZE 4096
104#define SFR_SIZE 4096
105
106#define QUEUE_SIZE (VIDC_IFACEQ_TABLE_SIZE + \
107 (VIDC_IFACEQ_QUEUE_SIZE * VIDC_IFACEQ_NUMQ))
108
109#define ALIGNED_QDSS_SIZE ALIGN(QDSS_SIZE, SZ_4K)
110#define ALIGNED_SFR_SIZE ALIGN(SFR_SIZE, SZ_4K)
111#define ALIGNED_QUEUE_SIZE ALIGN(QUEUE_SIZE, SZ_4K)
112#define SHARED_QSIZE ALIGN(ALIGNED_SFR_SIZE + ALIGNED_QUEUE_SIZE + \
113 ALIGNED_QDSS_SIZE, SZ_1M)
114
115enum vidc_hw_reg {
116 VIDC_HWREG_CTRL_STATUS = 0x1,
117 VIDC_HWREG_QTBL_INFO = 0x2,
118 VIDC_HWREG_QTBL_ADDR = 0x3,
119 VIDC_HWREG_CTRLR_RESET = 0x4,
120 VIDC_HWREG_IFACEQ_FWRXREQ = 0x5,
121 VIDC_HWREG_IFACEQ_FWTXREQ = 0x6,
122 VIDC_HWREG_VHI_SOFTINTEN = 0x7,
123 VIDC_HWREG_VHI_SOFTINTSTATUS = 0x8,
124 VIDC_HWREG_VHI_SOFTINTCLR = 0x9,
125 VIDC_HWREG_HVI_SOFTINTEN = 0xA,
126};
127
128struct vidc_mem_addr {
129 ion_phys_addr_t align_device_addr;
130 u8 *align_virtual_addr;
131 u32 mem_size;
132 struct msm_smem *mem_data;
133};
134
135struct vidc_iface_q_info {
136 void *q_hdr;
137 struct vidc_mem_addr q_array;
138};
139
140/*
141 * These are helper macros to iterate over various lists within
142 * venus_hfi_device->res. The intention is to cut down on a lot of boiler-plate
143 * code
144 */
145
146/* Read as "for each 'thing' in a set of 'thingies'" */
147#define venus_hfi_for_each_thing(__device, __thing, __thingy) \
148 venus_hfi_for_each_thing_continue(__device, __thing, __thingy, 0)
149
150#define venus_hfi_for_each_thing_reverse(__device, __thing, __thingy) \
151 venus_hfi_for_each_thing_reverse_continue(__device, __thing, __thingy, \
152 (__device)->res->__thingy##_set.count - 1)
153
154/* TODO: the __from parameter technically not required since we can figure it
155 * out with some pointer magic (i.e. __thing - __thing##_tbl[0]). If this macro
156 * sees extensive use, probably worth cleaning it up but for now omitting it
157 * since it introduces unneccessary complexity.
158 */
159#define venus_hfi_for_each_thing_continue(__device, __thing, __thingy, __from) \
160 for (__thing = &(__device)->res->\
161 __thingy##_set.__thingy##_tbl[__from]; \
162 __thing < &(__device)->res->__thingy##_set.__thingy##_tbl[0] + \
163 ((__device)->res->__thingy##_set.count - __from); \
164 ++__thing)
165
166#define venus_hfi_for_each_thing_reverse_continue(__device, __thing, __thingy, \
167 __from) \
168 for (__thing = &(__device)->res->\
169 __thingy##_set.__thingy##_tbl[__from]; \
170 __thing >= &(__device)->res->__thingy##_set.__thingy##_tbl[0]; \
171 --__thing)
172
173/* Regular set helpers */
174#define venus_hfi_for_each_regulator(__device, __rinfo) \
175 venus_hfi_for_each_thing(__device, __rinfo, regulator)
176
177#define venus_hfi_for_each_regulator_reverse(__device, __rinfo) \
178 venus_hfi_for_each_thing_reverse(__device, __rinfo, regulator)
179
180#define venus_hfi_for_each_regulator_reverse_continue(__device, __rinfo, \
181 __from) \
182 venus_hfi_for_each_thing_reverse_continue(__device, __rinfo, \
183 regulator, __from)
184
185/* Clock set helpers */
186#define venus_hfi_for_each_clock(__device, __cinfo) \
187 venus_hfi_for_each_thing(__device, __cinfo, clock)
188
189#define venus_hfi_for_each_clock_reverse(__device, __cinfo) \
190 venus_hfi_for_each_thing_reverse(__device, __cinfo, clock)
191
192#define venus_hfi_for_each_clock_reverse_continue(__device, __rinfo, \
193 __from) \
194 venus_hfi_for_each_thing_reverse_continue(__device, __rinfo, \
195 clock, __from)
196
197/* Bus set helpers */
198#define venus_hfi_for_each_bus(__device, __binfo) \
199 venus_hfi_for_each_thing(__device, __binfo, bus)
200#define venus_hfi_for_each_bus_reverse(__device, __binfo) \
201 venus_hfi_for_each_thing_reverse(__device, __binfo, bus)
202
Shivendra Kakraniac1f60e02017-04-13 00:07:26 -0700203/* Subcache set helpers */
204#define venus_hfi_for_each_subcache(__device, __sinfo) \
205 venus_hfi_for_each_thing(__device, __sinfo, subcache)
206#define venus_hfi_for_each_subcache_reverse(__device, __sinfo) \
207 venus_hfi_for_each_thing_reverse(__device, __sinfo, subcache)
Praneeth Paladugu6e6fbdb2017-01-16 15:43:01 -0800208
209/* Internal data used in vidc_hal not exposed to msm_vidc*/
210struct hal_data {
211 u32 irq;
212 phys_addr_t firmware_base;
213 u8 __iomem *register_base;
214 u32 register_size;
215};
216
Praneeth Paladugu6e6fbdb2017-01-16 15:43:01 -0800217struct venus_resources {
218 struct msm_vidc_fw fw;
Praneeth Paladugu6e6fbdb2017-01-16 15:43:01 -0800219};
220
221enum venus_hfi_state {
222 VENUS_STATE_DEINIT = 1,
223 VENUS_STATE_INIT,
224};
225
226struct venus_hfi_device {
227 struct list_head list;
228 struct list_head sess_head;
229 u32 intr_status;
230 u32 device_id;
231 u32 clk_freq;
232 u32 last_packet_type;
233 unsigned long clk_bitrate;
234 unsigned long scaled_rate;
235 struct msm_vidc_gov_data bus_vote;
236 bool power_enabled;
237 struct mutex lock;
238 msm_vidc_callback callback;
239 struct vidc_mem_addr iface_q_table;
240 struct vidc_mem_addr qdss;
241 struct vidc_mem_addr sfr;
242 struct vidc_mem_addr mem_addr;
243 struct vidc_iface_q_info iface_queues[VIDC_IFACEQ_NUMQ];
244 struct smem_client *hal_client;
245 struct hal_data *hal_data;
246 struct workqueue_struct *vidc_workq;
247 struct workqueue_struct *venus_pm_workq;
248 int spur_count;
249 int reg_count;
250 struct venus_resources resources;
251 struct msm_vidc_platform_resources *res;
252 enum venus_hfi_state state;
253 struct hfi_packetization_ops *pkt_ops;
254 enum hfi_packetization_type packetization_type;
255 struct msm_vidc_cb_info *response_pkt;
256 u8 *raw_packet;
257 struct pm_qos_request qos;
258 unsigned int skip_pc_count;
259 struct msm_vidc_capability *sys_init_capabilities;
260};
261
262void venus_hfi_delete_device(void *device);
263
264int venus_hfi_initialize(struct hfi_device *hdev, u32 device_id,
265 struct msm_vidc_platform_resources *res,
266 hfi_cmd_response_callback callback);
267bool venus_hfi_is_session_supported(unsigned long sessions_supported,
268 enum vidc_vote_data_session session_type);
269
270#endif