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