blob: 55f9a07fa846b5ab1075d62863fe9da9d4d18656 [file] [log] [blame]
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08001/* Copyright (c) 2012, Code Aurora Forum. 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#include <linux/slab.h>
15#include <linux/workqueue.h>
16#include <linux/interrupt.h>
17#include <linux/io.h>
Vinay Kalia94b221b2012-06-25 18:50:13 -070018#include <linux/delay.h>
Vinay Kaliabc9f60a2012-07-17 01:23:42 -070019#include <mach/ocmem.h>
20
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -080021#include <asm/memory.h>
22#include "vidc_hal.h"
23#include "vidc_hal_io.h"
Blaine Dietrichf1a7cff2012-07-23 12:14:18 -070024#include "msm_vidc_debug.h"
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -080025
26#define FIRMWARE_SIZE 0X00A00000
27#define REG_ADDR_OFFSET_BITMASK 0x000FFFFF
28
29/*Workaround for virtio */
Vinay Kalia68398a42012-06-22 18:36:12 -070030#define HFI_VIRTIO_FW_BIAS 0x0
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -080031
32struct hal_device_data hal_ctxt;
33
34static void hal_virtio_modify_cmd_packet(u8 *packet)
35{
36 struct hfi_cmd_sys_session_init_packet *sys_init;
37 struct hal_session *sess;
38 u8 i;
39
40 if (!packet) {
Blaine Dietrichf1a7cff2012-07-23 12:14:18 -070041 dprintk(VIDC_ERR, "Invalid Param");
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -080042 return;
43 }
44
45 sys_init = (struct hfi_cmd_sys_session_init_packet *)packet;
46 sess = (struct hal_session *) sys_init->session_id;
Ashray Kulkarnife72c452012-05-29 19:52:00 -070047 switch (sys_init->packet_type) {
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -080048 case HFI_CMD_SESSION_EMPTY_BUFFER:
49 if (sess->is_decoder) {
50 struct hfi_cmd_session_empty_buffer_compressed_packet
51 *pkt = (struct
52 hfi_cmd_session_empty_buffer_compressed_packet
53 *) packet;
54 pkt->packet_buffer -= HFI_VIRTIO_FW_BIAS;
55 } else {
56 struct
57 hfi_cmd_session_empty_buffer_uncompressed_plane0_packet
58 *pkt = (struct
59 hfi_cmd_session_empty_buffer_uncompressed_plane0_packet
60 *) packet;
61 pkt->packet_buffer -= HFI_VIRTIO_FW_BIAS;
62 }
63 break;
64 case HFI_CMD_SESSION_FILL_BUFFER:
65 {
66 struct hfi_cmd_session_fill_buffer_packet *pkt =
67 (struct hfi_cmd_session_fill_buffer_packet *)packet;
68 pkt->packet_buffer -= HFI_VIRTIO_FW_BIAS;
69 break;
70 }
71 case HFI_CMD_SESSION_SET_BUFFERS:
72 {
73 struct hfi_cmd_session_set_buffers_packet *pkt =
74 (struct hfi_cmd_session_set_buffers_packet *)packet;
75 if ((pkt->buffer_type == HFI_BUFFER_OUTPUT) ||
76 (pkt->buffer_type == HFI_BUFFER_OUTPUT2)) {
77 struct hfi_buffer_info *buff;
78 buff = (struct hfi_buffer_info *) pkt->rg_buffer_info;
79 buff->buffer_addr -= HFI_VIRTIO_FW_BIAS;
Ashray Kulkarnife72c452012-05-29 19:52:00 -070080 buff->extra_data_addr -= HFI_VIRTIO_FW_BIAS;
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -080081 } else {
82 for (i = 0; i < pkt->num_buffers; i++)
83 pkt->rg_buffer_info[i] -= HFI_VIRTIO_FW_BIAS;
84 }
85 break;
86 }
87 case HFI_CMD_SESSION_RELEASE_BUFFERS:
88 {
89 struct hfi_cmd_session_release_buffer_packet *pkt =
90 (struct hfi_cmd_session_release_buffer_packet *)packet;
Ashray Kulkarni1c72b392012-06-20 10:50:00 -070091 if ((pkt->buffer_type == HFI_BUFFER_OUTPUT) ||
92 (pkt->buffer_type == HFI_BUFFER_OUTPUT2)) {
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -080093 struct hfi_buffer_info *buff;
94 buff = (struct hfi_buffer_info *) pkt->rg_buffer_info;
95 buff->buffer_addr -= HFI_VIRTIO_FW_BIAS;
Ashray Kulkarnife72c452012-05-29 19:52:00 -070096 buff->extra_data_addr -= HFI_VIRTIO_FW_BIAS;
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -080097 } else {
98 for (i = 0; i < pkt->num_buffers; i++)
99 pkt->rg_buffer_info[i] -= HFI_VIRTIO_FW_BIAS;
100 }
101 break;
102 }
103 case HFI_CMD_SESSION_PARSE_SEQUENCE_HEADER:
104 {
105 struct hfi_cmd_session_parse_sequence_header_packet *pkt =
106 (struct hfi_cmd_session_parse_sequence_header_packet *)
107 packet;
108 pkt->packet_buffer -= HFI_VIRTIO_FW_BIAS;
109 break;
110 }
111 case HFI_CMD_SESSION_GET_SEQUENCE_HEADER:
112 {
113 struct hfi_cmd_session_get_sequence_header_packet *pkt =
114 (struct hfi_cmd_session_get_sequence_header_packet *)
115 packet;
116 pkt->packet_buffer -= HFI_VIRTIO_FW_BIAS;
117 break;
118 }
119 default:
120 break;
121 }
122}
123
124static int write_queue(void *info, u8 *packet, u32 *rx_req_is_set)
125{
126 struct hfi_queue_header *queue;
127 u32 packet_size_in_words, new_write_idx;
128 struct vidc_iface_q_info *qinfo;
129 u32 empty_space, read_idx;
130 u32 *write_ptr;
131
132 if (!info || !packet || !rx_req_is_set) {
Blaine Dietrichf1a7cff2012-07-23 12:14:18 -0700133 dprintk(VIDC_ERR, "Invalid Params");
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -0800134 return -EINVAL;
135 }
136
137 qinfo = (struct vidc_iface_q_info *) info;
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -0800138 hal_virtio_modify_cmd_packet(packet);
139
140 queue = (struct hfi_queue_header *) qinfo->q_hdr;
141
142 if (!queue) {
Blaine Dietrichf1a7cff2012-07-23 12:14:18 -0700143 dprintk(VIDC_ERR, "queue not present");
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -0800144 return -ENOENT;
145 }
146
147 packet_size_in_words = (*(u32 *)packet) >> 2;
Blaine Dietrichf1a7cff2012-07-23 12:14:18 -0700148 dprintk(VIDC_DBG, "Packet_size in words: %d", packet_size_in_words);
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -0800149
150 if (packet_size_in_words == 0) {
Blaine Dietrichf1a7cff2012-07-23 12:14:18 -0700151 dprintk(VIDC_ERR, "Zero packet size");
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -0800152 return -ENODATA;
153 }
154
155 read_idx = queue->qhdr_read_idx;
156
157 empty_space = (queue->qhdr_write_idx >= read_idx) ?
158 (queue->qhdr_q_size - (queue->qhdr_write_idx - read_idx)) :
159 (read_idx - queue->qhdr_write_idx);
Blaine Dietrichf1a7cff2012-07-23 12:14:18 -0700160 dprintk(VIDC_DBG, "Empty_space: %d", empty_space);
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -0800161 if (empty_space <= packet_size_in_words) {
162 queue->qhdr_tx_req = 1;
Blaine Dietrichf1a7cff2012-07-23 12:14:18 -0700163 dprintk(VIDC_ERR, "Insufficient size (%d) to write (%d)",
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -0800164 empty_space, packet_size_in_words);
165 return -ENOTEMPTY;
166 }
167
168 queue->qhdr_tx_req = 0;
169
170 new_write_idx = (queue->qhdr_write_idx + packet_size_in_words);
171 write_ptr = (u32 *)((qinfo->q_array.align_virtual_addr) +
172 (queue->qhdr_write_idx << 2));
Blaine Dietrichf1a7cff2012-07-23 12:14:18 -0700173 dprintk(VIDC_DBG, "Write Ptr: %d", (u32) write_ptr);
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -0800174 if (new_write_idx < queue->qhdr_q_size) {
175 memcpy(write_ptr, packet, packet_size_in_words << 2);
176 } else {
177 new_write_idx -= queue->qhdr_q_size;
178 memcpy(write_ptr, packet, (packet_size_in_words -
179 new_write_idx) << 2);
Vinay Kaliabddb1eb2012-09-24 18:01:57 -0700180 memcpy((void *)qinfo->q_array.align_virtual_addr,
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -0800181 packet + ((packet_size_in_words - new_write_idx) << 2),
182 new_write_idx << 2);
183 }
184 queue->qhdr_write_idx = new_write_idx;
185 *rx_req_is_set = (1 == queue->qhdr_rx_req) ? 1 : 0;
Blaine Dietrichf1a7cff2012-07-23 12:14:18 -0700186 dprintk(VIDC_DBG, "Out : ");
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -0800187 return 0;
188}
189
190static void hal_virtio_modify_msg_packet(u8 *packet)
191{
192 struct hfi_msg_sys_session_init_done_packet *sys_idle;
193 struct hal_session *sess;
194
195 if (!packet) {
Blaine Dietrichf1a7cff2012-07-23 12:14:18 -0700196 dprintk(VIDC_ERR, "Invalid Param: ");
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -0800197 return;
198 }
199
200 sys_idle = (struct hfi_msg_sys_session_init_done_packet *)packet;
201 sess = (struct hal_session *) sys_idle->session_id;
202
203 switch (sys_idle->packet_type) {
204 case HFI_MSG_SESSION_FILL_BUFFER_DONE:
205 if (sess->is_decoder) {
206 struct
207 hfi_msg_session_fbd_uncompressed_plane0_packet
208 *pkt_uc = (struct
209 hfi_msg_session_fbd_uncompressed_plane0_packet
210 *) packet;
211 pkt_uc->packet_buffer += HFI_VIRTIO_FW_BIAS;
212 } else {
213 struct
214 hfi_msg_session_fill_buffer_done_compressed_packet
215 *pkt = (struct
216 hfi_msg_session_fill_buffer_done_compressed_packet
217 *) packet;
218 pkt->packet_buffer += HFI_VIRTIO_FW_BIAS;
219 }
220 break;
221 case HFI_MSG_SESSION_EMPTY_BUFFER_DONE:
222 {
223 struct hfi_msg_session_empty_buffer_done_packet *pkt =
224 (struct hfi_msg_session_empty_buffer_done_packet *)packet;
225 pkt->packet_buffer += HFI_VIRTIO_FW_BIAS;
226 break;
227 }
228 case HFI_MSG_SESSION_GET_SEQUENCE_HEADER_DONE:
229 {
230 struct
231 hfi_msg_session_get_sequence_header_done_packet
232 *pkt =
233 (struct hfi_msg_session_get_sequence_header_done_packet *)
234 packet;
235 pkt->sequence_header += HFI_VIRTIO_FW_BIAS;
236 break;
237 }
238 default:
239 break;
240 }
241}
242
243static int read_queue(void *info, u8 *packet, u32 *pb_tx_req_is_set)
244{
245 struct hfi_queue_header *queue;
246 u32 packet_size_in_words, new_read_idx;
247 u32 *read_ptr;
248 struct vidc_iface_q_info *qinfo;
249
250 if (!info || !packet || !pb_tx_req_is_set) {
Ashray Kulkarni000b3822012-10-11 18:20:58 -0700251 dprintk(VIDC_ERR, "Invalid Params");
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -0800252 return -EINVAL;
253 }
254
255 qinfo = (struct vidc_iface_q_info *) info;
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -0800256 queue = (struct hfi_queue_header *) qinfo->q_hdr;
257
258 if (!queue) {
Blaine Dietrichf1a7cff2012-07-23 12:14:18 -0700259 dprintk(VIDC_ERR, "Queue memory is not allocated\n");
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -0800260 return -ENOMEM;
261 }
262
263 if (queue->qhdr_read_idx == queue->qhdr_write_idx) {
264 queue->qhdr_rx_req = 1;
265 *pb_tx_req_is_set = 0;
266 return -EPERM;
267 }
268
269 read_ptr = (u32 *)((qinfo->q_array.align_virtual_addr) +
270 (queue->qhdr_read_idx << 2));
271 packet_size_in_words = (*read_ptr) >> 2;
Blaine Dietrichf1a7cff2012-07-23 12:14:18 -0700272 dprintk(VIDC_DBG, "packet_size_in_words: %d", packet_size_in_words);
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -0800273 if (packet_size_in_words == 0) {
Blaine Dietrichf1a7cff2012-07-23 12:14:18 -0700274 dprintk(VIDC_ERR, "Zero packet size");
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -0800275 return -ENODATA;
276 }
277
278 new_read_idx = queue->qhdr_read_idx + packet_size_in_words;
Blaine Dietrichf1a7cff2012-07-23 12:14:18 -0700279 dprintk(VIDC_DBG, "Read Ptr: %d", (u32) new_read_idx);
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -0800280 if (new_read_idx < queue->qhdr_q_size) {
281 memcpy(packet, read_ptr,
282 packet_size_in_words << 2);
283 } else {
284 new_read_idx -= queue->qhdr_q_size;
285 memcpy(packet, read_ptr,
286 (packet_size_in_words - new_read_idx) << 2);
287 memcpy(packet + ((packet_size_in_words -
Vinay Kaliabddb1eb2012-09-24 18:01:57 -0700288 new_read_idx) << 2),
289 (u8 *)qinfo->q_array.align_virtual_addr,
290 new_read_idx << 2);
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -0800291 }
292
293 queue->qhdr_read_idx = new_read_idx;
294
295 if (queue->qhdr_read_idx != queue->qhdr_write_idx)
296 queue->qhdr_rx_req = 0;
297 else
298 queue->qhdr_rx_req = 1;
299
300 *pb_tx_req_is_set = (1 == queue->qhdr_tx_req) ? 1 : 0;
301 hal_virtio_modify_msg_packet(packet);
Blaine Dietrichf1a7cff2012-07-23 12:14:18 -0700302 dprintk(VIDC_DBG, "Out : ");
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -0800303 return 0;
304}
305
Vinay Kalia68398a42012-06-22 18:36:12 -0700306static int vidc_hal_alloc(void *mem, void *clnt, u32 size, u32 align, u32 flags,
307 int domain)
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -0800308{
309 struct vidc_mem_addr *vmem;
310 struct msm_smem *alloc;
Vinay Kaliae38c55f2012-08-16 19:37:28 -0700311 int rc = 0;
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -0800312
313 if (!mem || !clnt || !size) {
Ashray Kulkarni000b3822012-10-11 18:20:58 -0700314 dprintk(VIDC_ERR, "Invalid Params");
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -0800315 return -EINVAL;
316 }
317 vmem = (struct vidc_mem_addr *)mem;
Ashray Kulkarni000b3822012-10-11 18:20:58 -0700318 dprintk(VIDC_INFO, "start to alloc: size:%d, Flags: %d", size, flags);
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -0800319
Vinay Kaliae38c55f2012-08-16 19:37:28 -0700320 alloc = msm_smem_alloc(clnt, size, align, flags, domain, 1, 1);
Blaine Dietrichf1a7cff2012-07-23 12:14:18 -0700321 dprintk(VIDC_DBG, "Alloc done");
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -0800322 if (!alloc) {
Blaine Dietrichf1a7cff2012-07-23 12:14:18 -0700323 dprintk(VIDC_ERR, "Alloc failed\n");
Vinay Kaliae38c55f2012-08-16 19:37:28 -0700324 rc = -ENOMEM;
325 goto fail_smem_alloc;
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -0800326 }
Vinay Kaliae38c55f2012-08-16 19:37:28 -0700327 rc = msm_smem_clean_invalidate(clnt, alloc);
328 if (rc) {
Blaine Dietrichf1a7cff2012-07-23 12:14:18 -0700329 dprintk(VIDC_ERR, "NOTE: Failed to clean caches\n");
Vinay Kaliae38c55f2012-08-16 19:37:28 -0700330 goto fail_clean_cache;
331 }
Blaine Dietrichf1a7cff2012-07-23 12:14:18 -0700332 dprintk(VIDC_DBG, "vidc_hal_alloc:ptr=%p,size=%d",
Vinay Kaliae38c55f2012-08-16 19:37:28 -0700333 alloc->kvaddr, size);
334 vmem->mem_size = alloc->size;
335 vmem->mem_data = alloc;
336 vmem->align_virtual_addr = (u8 *) alloc->kvaddr;
337 vmem->align_device_addr = (u8 *)alloc->device_addr;
338 return rc;
339fail_clean_cache:
340 msm_smem_free(clnt, alloc);
341fail_smem_alloc:
342 return rc;
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -0800343}
344
345static void vidc_hal_free(struct smem_client *clnt, struct msm_smem *mem)
346{
347 msm_smem_free(clnt, mem);
348}
349
350static void write_register(u8 *base_addr, u32 reg, u32 value, u8 *vaddr)
351{
352 u32 hwiosymaddr = reg;
353
354 reg &= REG_ADDR_OFFSET_BITMASK;
355 if (reg == (u32)VIDC_CPU_CS_SCIACMDARG2) {
356 /* workaround to offset of FW bias */
357 struct hfi_queue_header *qhdr;
358 struct hfi_queue_table_header *qtbl_hdr =
359 (struct hfi_queue_table_header *)vaddr;
360
361 qhdr = VIDC_IFACEQ_GET_QHDR_START_ADDR(qtbl_hdr, 0);
362 qhdr->qhdr_start_addr -= HFI_VIRTIO_FW_BIAS;
363
364 qhdr = VIDC_IFACEQ_GET_QHDR_START_ADDR(qtbl_hdr, 1);
365 qhdr->qhdr_start_addr -= HFI_VIRTIO_FW_BIAS;
366
367 qhdr = VIDC_IFACEQ_GET_QHDR_START_ADDR(qtbl_hdr, 2);
368 qhdr->qhdr_start_addr -= HFI_VIRTIO_FW_BIAS;
369 value -= HFI_VIRTIO_FW_BIAS;
370 }
371
372 hwiosymaddr = ((u32)base_addr + (hwiosymaddr));
Blaine Dietrichf1a7cff2012-07-23 12:14:18 -0700373 dprintk(VIDC_DBG, "Base addr: 0x%x, written to: 0x%x, Value: 0x%x...",
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -0800374 (u32)base_addr, hwiosymaddr, value);
375 writel_relaxed(value, hwiosymaddr);
376 wmb();
377}
378
379static int read_register(u8 *base_addr, u32 reg)
380{
381 int rc = readl_relaxed((u32)base_addr + reg);
382 rmb();
383 return rc;
384}
385
386static int vidc_hal_iface_cmdq_write(struct hal_device *device, void *pkt)
387{
388 u32 rx_req_is_set = 0;
389 struct vidc_iface_q_info *q_info;
390 int result = -EPERM;
391
392 if (!device || !pkt) {
Ashray Kulkarni000b3822012-10-11 18:20:58 -0700393 dprintk(VIDC_ERR, "Invalid Params");
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -0800394 return -EINVAL;
395 }
396
397 spin_lock(&device->write_lock);
398 q_info = &device->iface_queues[VIDC_IFACEQ_CMDQ_IDX];
399 if (!q_info) {
Blaine Dietrichf1a7cff2012-07-23 12:14:18 -0700400 dprintk(VIDC_ERR, "cannot write to shared Q's");
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -0800401 goto err_q_write;
402 }
403
404 if (!write_queue(q_info, (u8 *)pkt, &rx_req_is_set)) {
405 if (rx_req_is_set)
406 write_register(device->hal_data->register_base_addr,
407 VIDC_CPU_IC_SOFTINT,
408 1 << VIDC_CPU_IC_SOFTINT_H2A_SHFT, 0);
409 result = 0;
410 } else {
Blaine Dietrichf1a7cff2012-07-23 12:14:18 -0700411 dprintk(VIDC_ERR, "vidc_hal_iface_cmdq_write:queue_full");
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -0800412 }
413err_q_write:
414 spin_unlock(&device->write_lock);
415 return result;
416}
417
418int vidc_hal_iface_msgq_read(struct hal_device *device, void *pkt)
419{
420 u32 tx_req_is_set = 0;
421 int rc = 0;
422 struct vidc_iface_q_info *q_info;
423
424 if (!pkt) {
Ashray Kulkarni000b3822012-10-11 18:20:58 -0700425 dprintk(VIDC_ERR, "Invalid Params");
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -0800426 return -EINVAL;
427 }
428 spin_lock(&device->read_lock);
429 if (device->iface_queues[VIDC_IFACEQ_MSGQ_IDX].
430 q_array.align_virtual_addr == 0) {
Blaine Dietrichf1a7cff2012-07-23 12:14:18 -0700431 dprintk(VIDC_ERR, "cannot read from shared MSG Q's");
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -0800432 rc = -ENODATA;
433 goto read_error;
434 }
435 q_info = &device->iface_queues[VIDC_IFACEQ_MSGQ_IDX];
436
437 if (!read_queue(q_info, (u8 *)pkt, &tx_req_is_set)) {
438 if (tx_req_is_set)
439 write_register(device->hal_data->register_base_addr,
440 VIDC_CPU_IC_SOFTINT,
441 1 << VIDC_CPU_IC_SOFTINT_H2A_SHFT, 0);
442 rc = 0;
443 } else {
Blaine Dietrichf1a7cff2012-07-23 12:14:18 -0700444 dprintk(VIDC_INFO, "vidc_hal_iface_msgq_read:queue_empty");
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -0800445 rc = -ENODATA;
446 }
447read_error:
448 spin_unlock(&device->read_lock);
449 return rc;
450}
451
452int vidc_hal_iface_dbgq_read(struct hal_device *device, void *pkt)
453{
454 u32 tx_req_is_set = 0;
455 int rc = 0;
456 struct vidc_iface_q_info *q_info;
457
458 if (!pkt) {
Ashray Kulkarni000b3822012-10-11 18:20:58 -0700459 dprintk(VIDC_ERR, "Invalid Params");
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -0800460 return -EINVAL;
461 }
462 spin_lock(&device->read_lock);
463 if (device->iface_queues[VIDC_IFACEQ_DBGQ_IDX].
464 q_array.align_virtual_addr == 0) {
Blaine Dietrichf1a7cff2012-07-23 12:14:18 -0700465 dprintk(VIDC_ERR, "cannot read from shared DBG Q's");
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -0800466 rc = -ENODATA;
467 goto dbg_error;
468 }
469 q_info = &device->iface_queues[VIDC_IFACEQ_DBGQ_IDX];
470 if (!read_queue(q_info, (u8 *)pkt, &tx_req_is_set)) {
471 if (tx_req_is_set)
472 write_register(device->hal_data->register_base_addr,
473 VIDC_CPU_IC_SOFTINT,
474 1 << VIDC_CPU_IC_SOFTINT_H2A_SHFT, 0);
475 rc = 0;
476 } else {
Blaine Dietrichf1a7cff2012-07-23 12:14:18 -0700477 dprintk(VIDC_INFO, "vidc_hal_iface_dbgq_read:queue_empty");
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -0800478 rc = -ENODATA;
479 }
480dbg_error:
481 spin_unlock(&device->read_lock);
482 return rc;
483}
484
485static void vidc_hal_set_queue_hdr_defaults(struct hfi_queue_header *q_hdr)
486{
487 q_hdr->qhdr_status = 0x1;
488 q_hdr->qhdr_type = VIDC_IFACEQ_DFLT_QHDR;
Ashray Kulkarni3dbe9992012-08-20 12:22:57 -0700489 q_hdr->qhdr_q_size = VIDC_IFACEQ_QUEUE_SIZE / 4;
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -0800490 q_hdr->qhdr_pkt_size = 0;
491 q_hdr->qhdr_rx_wm = 0x1;
492 q_hdr->qhdr_tx_wm = 0x1;
493 q_hdr->qhdr_rx_req = 0x1;
494 q_hdr->qhdr_tx_req = 0x0;
495 q_hdr->qhdr_rx_irq_status = 0x0;
496 q_hdr->qhdr_tx_irq_status = 0x0;
497 q_hdr->qhdr_read_idx = 0x0;
498 q_hdr->qhdr_write_idx = 0x0;
499}
500
501static void vidc_hal_interface_queues_release(struct hal_device *device)
502{
503 int i;
504 for (i = 0; i < VIDC_IFACEQ_NUMQ; i++) {
505 vidc_hal_free(device->hal_client,
506 device->iface_queues[i].q_array.mem_data);
507 device->iface_queues[i].q_hdr = NULL;
508 device->iface_queues[i].q_array.mem_data = NULL;
509 device->iface_queues[i].q_array.align_virtual_addr = NULL;
510 device->iface_queues[i].q_array.align_device_addr = NULL;
511 }
512 vidc_hal_free(device->hal_client,
513 device->iface_q_table.mem_data);
514 device->iface_q_table.align_virtual_addr = NULL;
515 device->iface_q_table.align_device_addr = NULL;
516 msm_smem_delete_client(device->hal_client);
517 device->hal_client = NULL;
518}
519
Vinay Kalia68398a42012-06-22 18:36:12 -0700520static int vidc_hal_interface_queues_init(struct hal_device *dev, int domain)
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -0800521{
522 struct hfi_queue_table_header *q_tbl_hdr;
523 struct hfi_queue_header *q_hdr;
524 u8 i;
525 int rc = 0;
526 struct vidc_iface_q_info *iface_q;
527
528 rc = vidc_hal_alloc((void *) &dev->iface_q_table,
529 dev->hal_client,
Vinay Kaliae38c55f2012-08-16 19:37:28 -0700530 VIDC_IFACEQ_TABLE_SIZE, 1, SMEM_UNCACHED, domain);
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -0800531 if (rc) {
Ashray Kulkarnib6734502012-08-24 13:00:22 -0700532 dprintk(VIDC_ERR, "iface_q_table_alloc_fail");
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -0800533 return -ENOMEM;
534 }
535 q_tbl_hdr = (struct hfi_queue_table_header *)
536 dev->iface_q_table.align_virtual_addr;
537 q_tbl_hdr->qtbl_version = 0;
538 q_tbl_hdr->qtbl_size = VIDC_IFACEQ_TABLE_SIZE;
539 q_tbl_hdr->qtbl_qhdr0_offset = sizeof(
540 struct hfi_queue_table_header);
541 q_tbl_hdr->qtbl_qhdr_size = sizeof(
542 struct hfi_queue_header);
543 q_tbl_hdr->qtbl_num_q = VIDC_IFACEQ_NUMQ;
544 q_tbl_hdr->qtbl_num_active_q = VIDC_IFACEQ_NUMQ;
545
546 for (i = 0; i < VIDC_IFACEQ_NUMQ; i++) {
547 iface_q = &dev->iface_queues[i];
548 rc = vidc_hal_alloc((void *) &iface_q->q_array,
549 dev->hal_client, VIDC_IFACEQ_QUEUE_SIZE,
Vinay Kaliae38c55f2012-08-16 19:37:28 -0700550 1, SMEM_UNCACHED, domain);
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -0800551 if (rc) {
Ashray Kulkarnib6734502012-08-24 13:00:22 -0700552 dprintk(VIDC_ERR, "iface_q_table_alloc[%d]_fail", i);
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -0800553 vidc_hal_interface_queues_release(dev);
554 return -ENOMEM;
555 } else {
556 iface_q->q_hdr =
557 VIDC_IFACEQ_GET_QHDR_START_ADDR(
558 dev->iface_q_table.align_virtual_addr, i);
559 vidc_hal_set_queue_hdr_defaults(iface_q->q_hdr);
560 }
561 }
562
563 iface_q = &dev->iface_queues[VIDC_IFACEQ_CMDQ_IDX];
564 q_hdr = iface_q->q_hdr;
565 q_hdr->qhdr_start_addr = (u32)
566 iface_q->q_array.align_device_addr;
567 q_hdr->qhdr_type |= HFI_Q_ID_HOST_TO_CTRL_CMD_Q;
568
569 iface_q = &dev->iface_queues[VIDC_IFACEQ_MSGQ_IDX];
570 q_hdr = iface_q->q_hdr;
571 q_hdr->qhdr_start_addr = (u32)
572 iface_q->q_array.align_device_addr;
573 q_hdr->qhdr_type |= HFI_Q_ID_CTRL_TO_HOST_MSG_Q;
574
575 iface_q = &dev->iface_queues[VIDC_IFACEQ_DBGQ_IDX];
576 q_hdr = iface_q->q_hdr;
577 q_hdr->qhdr_start_addr = (u32)
578 iface_q->q_array.align_device_addr;
579 q_hdr->qhdr_type |= HFI_Q_ID_CTRL_TO_HOST_DEBUG_Q;
580 write_register(dev->hal_data->register_base_addr,
581 VIDC_CPU_CS_SCIACMDARG2,
582 (u32) dev->iface_q_table.align_device_addr,
583 dev->iface_q_table.align_virtual_addr);
584 write_register(dev->hal_data->register_base_addr,
585 VIDC_CPU_CS_SCIACMDARG1, 0x01,
586 dev->iface_q_table.align_virtual_addr);
587 return 0;
588}
589
590static int vidc_hal_core_start_cpu(struct hal_device *device)
591{
592 u32 ctrl_status = 0, count = 0, rc = 0;
Vinay Kalia15e870b2012-09-10 15:30:23 -0700593 int max_tries = 100;
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -0800594 write_register(device->hal_data->register_base_addr,
Ashray Kulkarniae3e91a2012-10-12 17:37:37 -0700595 VIDC_WRAPPER_INTR_MASK, 0x8, 0);
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -0800596 write_register(device->hal_data->register_base_addr,
597 VIDC_CPU_CS_SCIACMDARG3, 1, 0);
Vinay Kalia15e870b2012-09-10 15:30:23 -0700598 while (!ctrl_status && count < max_tries) {
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -0800599 ctrl_status = read_register(
600 device->hal_data->register_base_addr,
601 VIDC_CPU_CS_SCIACMDARG0);
Vinay Kalia94b221b2012-06-25 18:50:13 -0700602 usleep_range(500, 1000);
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -0800603 count++;
604 }
Vinay Kalia15e870b2012-09-10 15:30:23 -0700605 if (count >= max_tries)
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -0800606 rc = -ETIME;
607 return rc;
608}
609
Vinay Kaliacdf8d0c2012-08-28 12:07:36 -0700610static void set_vbif_registers(struct hal_device *device)
611{
Vinay Kaliab717b9d2012-09-14 12:00:45 -0700612 /*Disable Dynamic clock gating for Venus VBIF*/
613 write_register(device->hal_data->register_base_addr,
614 VIDC_VENUS_VBIF_CLK_ON, 1, 0);
Vinay Kaliacdf8d0c2012-08-28 12:07:36 -0700615 write_register(device->hal_data->register_base_addr,
Ashray Kulkarni36f8d362012-10-18 17:01:06 -0700616 VIDC_VBIF_OUT_AXI_AOOO_EN, 0x00001FFF, 0);
Vinay Kaliacdf8d0c2012-08-28 12:07:36 -0700617 write_register(device->hal_data->register_base_addr,
Ashray Kulkarni36f8d362012-10-18 17:01:06 -0700618 VIDC_VBIF_OUT_AXI_AOOO, 0x1FFF1FFF, 0);
Vinay Kaliacdf8d0c2012-08-28 12:07:36 -0700619 write_register(device->hal_data->register_base_addr,
Vinay Kalia15e870b2012-09-10 15:30:23 -0700620 VIDC_VBIF_IN_RD_LIM_CONF0, 0x10101001, 0);
Vinay Kaliacdf8d0c2012-08-28 12:07:36 -0700621 write_register(device->hal_data->register_base_addr,
Vinay Kalia15e870b2012-09-10 15:30:23 -0700622 VIDC_VBIF_IN_RD_LIM_CONF1, 0x10101010, 0);
Vinay Kaliacdf8d0c2012-08-28 12:07:36 -0700623 write_register(device->hal_data->register_base_addr,
Vinay Kalia15e870b2012-09-10 15:30:23 -0700624 VIDC_VBIF_IN_RD_LIM_CONF2, 0x10101010, 0);
Vinay Kaliacdf8d0c2012-08-28 12:07:36 -0700625 write_register(device->hal_data->register_base_addr,
Vinay Kalia15e870b2012-09-10 15:30:23 -0700626 VIDC_VBIF_IN_RD_LIM_CONF3, 0x00000010, 0);
Vinay Kaliacdf8d0c2012-08-28 12:07:36 -0700627 write_register(device->hal_data->register_base_addr,
Vinay Kalia15e870b2012-09-10 15:30:23 -0700628 VIDC_VBIF_IN_WR_LIM_CONF0, 0x1010100f, 0);
Vinay Kaliacdf8d0c2012-08-28 12:07:36 -0700629 write_register(device->hal_data->register_base_addr,
Vinay Kalia15e870b2012-09-10 15:30:23 -0700630 VIDC_VBIF_IN_WR_LIM_CONF1, 0x10101010, 0);
631 write_register(device->hal_data->register_base_addr,
632 VIDC_VBIF_IN_WR_LIM_CONF2, 0x10101010, 0);
633 write_register(device->hal_data->register_base_addr,
634 VIDC_VBIF_IN_WR_LIM_CONF3, 0x00000010, 0);
635 write_register(device->hal_data->register_base_addr,
636 VIDC_VBIF_OUT_RD_LIM_CONF0, 0x00001010, 0);
637 write_register(device->hal_data->register_base_addr,
638 VIDC_VBIF_OUT_WR_LIM_CONF0, 0x00001010, 0);
639 write_register(device->hal_data->register_base_addr,
640 VIDC_VBIF_ARB_CTL, 0x00000030, 0);
Vinay Kaliab717b9d2012-09-14 12:00:45 -0700641 write_register(device->hal_data->register_base_addr,
Ashray Kulkarni36f8d362012-10-18 17:01:06 -0700642 VIDC_VENUS_VBIF_DDR_OUT_MAX_BURST, 0x00000707, 0);
643 write_register(device->hal_data->register_base_addr,
644 VIDC_VENUS_VBIF_OCMEM_OUT_MAX_BURST, 0x00000707, 0);
645 write_register(device->hal_data->register_base_addr,
646 VIDC_VENUS_VBIF_ROUND_ROBIN_QOS_ARB, 0x00000001, 0);
647 write_register(device->hal_data->register_base_addr,
Vinay Kaliab717b9d2012-09-14 12:00:45 -0700648 VIDC_VENUS0_WRAPPER_VBIF_REQ_PRIORITY, 0x5555556, 0);
Ashray Kulkarni36f8d362012-10-18 17:01:06 -0700649 write_register(device->hal_data->register_base_addr,
650 VIDC_VENUS0_WRAPPER_VBIF_PRIORITY_LEVEL, 0, 0);
Vinay Kaliacdf8d0c2012-08-28 12:07:36 -0700651}
652
Ashray Kulkarnicde78522012-06-28 18:14:50 -0700653static int vidc_hal_sys_set_debug(struct hal_device *device, int debug)
654{
655 struct hfi_debug_config *hfi;
656 u8 packet[VIDC_IFACEQ_VAR_SMALL_PKT_SIZE];
657 struct hfi_cmd_sys_set_property_packet *pkt =
658 (struct hfi_cmd_sys_set_property_packet *) &packet;
659 pkt->size = sizeof(struct hfi_cmd_sys_set_property_packet) +
660 sizeof(struct hfi_debug_config) + sizeof(u32);
661 pkt->packet_type = HFI_CMD_SYS_SET_PROPERTY;
662 pkt->num_properties = 1;
663 pkt->rg_property_data[0] = HFI_PROPERTY_SYS_DEBUG_CONFIG;
664 hfi = (struct hfi_debug_config *) &pkt->rg_property_data[1];
665 hfi->debug_config = debug;
666 if (vidc_hal_iface_cmdq_write(device, pkt))
667 return -ENOTEMPTY;
668 return 0;
669}
670
Vinay Kalia68398a42012-06-22 18:36:12 -0700671int vidc_hal_core_init(void *device, int domain)
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -0800672{
673 struct hfi_cmd_sys_init_packet pkt;
674 int rc = 0;
675 struct hal_device *dev;
676
677 if (device) {
678 dev = device;
679 } else {
Ashray Kulkarnib6734502012-08-24 13:00:22 -0700680 dprintk(VIDC_ERR, "Invalid device");
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -0800681 return -ENODEV;
682 }
683 enable_irq(dev->hal_data->irq);
684 INIT_LIST_HEAD(&dev->sess_head);
685 spin_lock_init(&dev->read_lock);
686 spin_lock_init(&dev->write_lock);
Vinay Kaliacdf8d0c2012-08-28 12:07:36 -0700687 set_vbif_registers(dev);
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -0800688 if (!dev->hal_client) {
689 dev->hal_client = msm_smem_new_client(SMEM_ION);
690 if (dev->hal_client == NULL) {
Blaine Dietrichf1a7cff2012-07-23 12:14:18 -0700691 dprintk(VIDC_ERR, "Failed to alloc ION_Client");
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -0800692 rc = -ENODEV;
693 goto err_no_mem;
694 }
695
Blaine Dietrichf1a7cff2012-07-23 12:14:18 -0700696 dprintk(VIDC_DBG, "Device_Virt_Address : 0x%x,"
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -0800697 "Register_Virt_Addr: 0x%x",
Vinay Kalia68398a42012-06-22 18:36:12 -0700698 dev->hal_data->device_base_addr,
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -0800699 (u32) dev->hal_data->register_base_addr);
700
Vinay Kalia68398a42012-06-22 18:36:12 -0700701 rc = vidc_hal_interface_queues_init(dev, domain);
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -0800702 if (rc) {
Blaine Dietrichf1a7cff2012-07-23 12:14:18 -0700703 dprintk(VIDC_ERR, "failed to init queues");
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -0800704 rc = -ENOMEM;
705 goto err_no_mem;
706 }
707 } else {
Blaine Dietrichf1a7cff2012-07-23 12:14:18 -0700708 dprintk(VIDC_ERR, "hal_client exists");
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -0800709 rc = -EEXIST;
710 goto err_no_mem;
711 }
712 rc = vidc_hal_core_start_cpu(dev);
713 if (rc) {
Blaine Dietrichf1a7cff2012-07-23 12:14:18 -0700714 dprintk(VIDC_ERR, "Failed to start core");
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -0800715 rc = -ENODEV;
716 goto err_no_dev;
717 }
718 pkt.size = sizeof(struct hfi_cmd_sys_init_packet);
Ashray Kulkarnife72c452012-05-29 19:52:00 -0700719 pkt.packet_type = HFI_CMD_SYS_INIT;
720 pkt.arch_type = HFI_ARCH_OX_OFFSET;
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -0800721 if (vidc_hal_iface_cmdq_write(dev, &pkt)) {
722 rc = -ENOTEMPTY;
723 goto err_write_fail;
724 }
725 return rc;
726err_no_dev:
727err_write_fail:
728err_no_mem:
729 disable_irq_nosync(dev->hal_data->irq);
730 return rc;
731}
732
733int vidc_hal_core_release(void *device)
734{
735 struct hal_device *dev;
736 if (device) {
737 dev = device;
738 } else {
Ashray Kulkarnib6734502012-08-24 13:00:22 -0700739 dprintk(VIDC_ERR, "invalid device");
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -0800740 return -ENODEV;
741 }
742 write_register(dev->hal_data->register_base_addr,
743 VIDC_CPU_CS_SCIACMDARG3, 0, 0);
Vinay Kalia40c3ae82012-07-09 15:23:02 -0700744 disable_irq_nosync(dev->hal_data->irq);
745 vidc_hal_interface_queues_release(dev);
Blaine Dietrichf1a7cff2012-07-23 12:14:18 -0700746 dprintk(VIDC_INFO, "HAL exited\n");
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -0800747 return 0;
748}
749
750int vidc_hal_core_pc_prep(void *device)
751{
752 struct hfi_cmd_sys_pc_prep_packet pkt;
753 int rc = 0;
754 struct hal_device *dev;
755
756 if (device) {
757 dev = device;
758 } else {
Ashray Kulkarnib6734502012-08-24 13:00:22 -0700759 dprintk(VIDC_ERR, "invalid device");
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -0800760 return -ENODEV;
761 }
762 pkt.size = sizeof(struct hfi_cmd_sys_pc_prep_packet);
763 pkt.packet_type = HFI_CMD_SYS_PC_PREP;
764 if (vidc_hal_iface_cmdq_write(dev, &pkt))
765 rc = -ENOTEMPTY;
766 return rc;
767}
768
769static void vidc_hal_core_clear_interrupt(struct hal_device *device)
770{
771 u32 intr_status = 0;
772
773 if (!device->callback)
774 return;
775
776 intr_status = read_register(
777 device->hal_data->register_base_addr,
778 VIDC_WRAPPER_INTR_STATUS);
779
780 if ((intr_status & VIDC_WRAPPER_INTR_STATUS_A2H_BMSK) ||
781 (intr_status & VIDC_WRAPPER_INTR_STATUS_A2HWD_BMSK)) {
782 device->intr_status |= intr_status;
Blaine Dietrichf1a7cff2012-07-23 12:14:18 -0700783 dprintk(VIDC_DBG, "INTERRUPT for device: 0x%x: "
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -0800784 "times: %d interrupt_status: %d",
785 (u32) device, ++device->reg_count, intr_status);
786 } else {
Ashray Kulkarni000b3822012-10-11 18:20:58 -0700787 dprintk(VIDC_INFO, "SPURIOUS_INTR for device: 0x%x: "
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -0800788 "times: %d interrupt_status: %d",
789 (u32) device, ++device->spur_count, intr_status);
790 }
791 write_register(device->hal_data->register_base_addr,
792 VIDC_CPU_CS_A2HSOFTINTCLR, 1, 0);
793 write_register(device->hal_data->register_base_addr,
794 VIDC_WRAPPER_INTR_CLEAR, intr_status, 0);
Blaine Dietrichf1a7cff2012-07-23 12:14:18 -0700795 dprintk(VIDC_DBG, "Cleared WRAPPER/A2H interrupt");
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -0800796}
797
798int vidc_hal_core_set_resource(void *device,
799 struct vidc_resource_hdr *resource_hdr, void *resource_value)
800{
801 struct hfi_cmd_sys_set_resource_packet *pkt;
802 u8 packet[VIDC_IFACEQ_VAR_SMALL_PKT_SIZE];
803 int rc = 0;
804 struct hal_device *dev;
805
806 if (!device || !resource_hdr || !resource_value) {
Ashray Kulkarnib6734502012-08-24 13:00:22 -0700807 dprintk(VIDC_ERR, "set_res: Invalid Params");
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -0800808 return -EINVAL;
809 } else {
810 dev = device;
811 }
812
813 pkt = (struct hfi_cmd_sys_set_resource_packet *) packet;
814
815 pkt->size = sizeof(struct hfi_cmd_sys_set_resource_packet);
816 pkt->packet_type = HFI_CMD_SYS_SET_RESOURCE;
817 pkt->resource_handle = resource_hdr->resource_handle;
818
819 switch (resource_hdr->resource_id) {
820 case VIDC_RESOURCE_OCMEM:
821 {
Ashray Kulkarnife72c452012-05-29 19:52:00 -0700822 struct hfi_resource_ocmem *hfioc_mem =
823 (struct hfi_resource_ocmem *)
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -0800824 &pkt->rg_resource_data[0];
Vinay Kaliabc9f60a2012-07-17 01:23:42 -0700825 struct ocmem_buf *ocmem =
826 (struct ocmem_buf *) resource_value;
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -0800827
828 pkt->resource_type = HFI_RESOURCE_OCMEM;
Vinay Kaliabc9f60a2012-07-17 01:23:42 -0700829 hfioc_mem->size = (u32) ocmem->len;
830 hfioc_mem->mem = (u8 *) ocmem->addr;
Ashray Kulkarnife72c452012-05-29 19:52:00 -0700831 pkt->size += sizeof(struct hfi_resource_ocmem);
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -0800832 if (vidc_hal_iface_cmdq_write(dev, pkt))
833 rc = -ENOTEMPTY;
834 break;
835 }
836 default:
Ashray Kulkarnib6734502012-08-24 13:00:22 -0700837 dprintk(VIDC_INFO, "Invalid res_id in set_res %d",
Blaine Dietrichf1a7cff2012-07-23 12:14:18 -0700838 resource_hdr->resource_id);
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -0800839 break;
840 }
841 return rc;
842}
843
844int vidc_hal_core_release_resource(void *device,
845 struct vidc_resource_hdr *resource_hdr)
846{
847 struct hfi_cmd_sys_release_resource_packet pkt;
848 int rc = 0;
849 struct hal_device *dev;
850
851 if (!device || !resource_hdr) {
Ashray Kulkarnib6734502012-08-24 13:00:22 -0700852 dprintk(VIDC_ERR, "Inv-Params in rel_res");
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -0800853 return -EINVAL;
854 } else {
855 dev = device;
856 }
857
858 pkt.size = sizeof(struct hfi_cmd_sys_release_resource_packet);
859 pkt.packet_type = HFI_CMD_SYS_RELEASE_RESOURCE;
860 pkt.resource_type = resource_hdr->resource_id;
861 pkt.resource_handle = resource_hdr->resource_handle;
862
863 if (vidc_hal_iface_cmdq_write(dev, &pkt))
864 rc = -ENOTEMPTY;
865 return rc;
866}
867
868int vidc_hal_core_ping(void *device)
869{
870 struct hfi_cmd_sys_ping_packet pkt;
871 int rc = 0;
872 struct hal_device *dev;
873
874 if (device) {
875 dev = device;
876 } else {
Ashray Kulkarnib6734502012-08-24 13:00:22 -0700877 dprintk(VIDC_ERR, "invalid device");
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -0800878 return -ENODEV;
879 }
880 pkt.size = sizeof(struct hfi_cmd_sys_ping_packet);
881 pkt.packet_type = HFI_CMD_SYS_PING;
882
883 if (vidc_hal_iface_cmdq_write(dev, &pkt))
884 rc = -ENOTEMPTY;
885 return rc;
886}
Ashray Kulkarnife72c452012-05-29 19:52:00 -0700887static u32 get_hfi_buffer(int hal_buffer)
888{
889 u32 buffer;
890 switch (hal_buffer) {
891 case HAL_BUFFER_INPUT:
892 buffer = HFI_BUFFER_INPUT;
893 break;
894 case HAL_BUFFER_OUTPUT:
895 buffer = HFI_BUFFER_OUTPUT;
896 break;
897 case HAL_BUFFER_OUTPUT2:
898 buffer = HFI_BUFFER_OUTPUT;
899 break;
900 case HAL_BUFFER_EXTRADATA_INPUT:
901 buffer = HFI_BUFFER_EXTRADATA_INPUT;
902 break;
903 case HAL_BUFFER_EXTRADATA_OUTPUT:
904 buffer = HFI_BUFFER_EXTRADATA_OUTPUT;
905 break;
906 case HAL_BUFFER_EXTRADATA_OUTPUT2:
907 buffer = HFI_BUFFER_EXTRADATA_OUTPUT2;
908 break;
909 case HAL_BUFFER_INTERNAL_SCRATCH:
910 buffer = HFI_BUFFER_INTERNAL_SCRATCH;
911 break;
912 case HAL_BUFFER_INTERNAL_PERSIST:
913 buffer = HFI_BUFFER_INTERNAL_PERSIST;
914 break;
915 default:
Ashray Kulkarnib6734502012-08-24 13:00:22 -0700916 dprintk(VIDC_ERR, "Invalid buffer :0x%x\n",
917 hal_buffer);
Ashray Kulkarnife72c452012-05-29 19:52:00 -0700918 buffer = 0;
919 break;
920 }
921 return buffer;
922}
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -0800923int vidc_hal_session_set_property(void *sess,
924 enum hal_property ptype, void *pdata)
925{
926 u8 packet[VIDC_IFACEQ_VAR_LARGE_PKT_SIZE];
927 struct hfi_cmd_session_set_property_packet *pkt =
928 (struct hfi_cmd_session_set_property_packet *) &packet;
929 struct hal_session *session;
930
931 if (!sess || !pdata) {
Ashray Kulkarnib6734502012-08-24 13:00:22 -0700932 dprintk(VIDC_ERR, "Invalid Params");
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -0800933 return -EINVAL;
934 } else {
935 session = sess;
936 }
937
Ashray Kulkarnib6734502012-08-24 13:00:22 -0700938 dprintk(VIDC_INFO, "in set_prop,with prop id: 0x%x", ptype);
Ashray Kulkarni1c72b392012-06-20 10:50:00 -0700939 pkt->size = sizeof(struct hfi_cmd_session_set_property_packet);
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -0800940 pkt->packet_type = HFI_CMD_SESSION_SET_PROPERTY;
941 pkt->session_id = (u32) session;
942 pkt->num_properties = 1;
943
944 switch (ptype) {
945 case HAL_CONFIG_FRAME_RATE:
Ashray Kulkarni1ccbc912012-03-23 16:26:52 -0700946 {
Ashray Kulkarnife72c452012-05-29 19:52:00 -0700947 struct hfi_frame_rate *hfi;
948 u32 buffer;
949 struct hal_frame_rate *prop =
950 (struct hal_frame_rate *) pdata;
Ashray Kulkarni1ccbc912012-03-23 16:26:52 -0700951 pkt->rg_property_data[0] = HFI_PROPERTY_CONFIG_FRAME_RATE;
Ashray Kulkarnife72c452012-05-29 19:52:00 -0700952 hfi = (struct hfi_frame_rate *) &pkt->rg_property_data[1];
953 buffer = get_hfi_buffer(prop->buffer_type);
954 if (buffer)
955 hfi->buffer_type = buffer;
956 else
957 return -EINVAL;
958 hfi->frame_rate = prop->frame_rate;
Ashray Kulkarni1ccbc912012-03-23 16:26:52 -0700959 pkt->size += sizeof(u32) + sizeof(struct hfi_frame_rate);
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -0800960 break;
Ashray Kulkarni1ccbc912012-03-23 16:26:52 -0700961 }
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -0800962 case HAL_PARAM_UNCOMPRESSED_FORMAT_SELECT:
963 {
Ashray Kulkarnife72c452012-05-29 19:52:00 -0700964 u32 buffer;
965 struct hfi_uncompressed_format_select *hfi;
966 struct hal_uncompressed_format_select *prop =
967 (struct hal_uncompressed_format_select *) pdata;
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -0800968 pkt->rg_property_data[0] =
969 HFI_PROPERTY_PARAM_UNCOMPRESSED_FORMAT_SELECT;
Ashray Kulkarnife72c452012-05-29 19:52:00 -0700970 hfi = (struct hfi_uncompressed_format_select *)
971 &pkt->rg_property_data[1];
972 buffer = get_hfi_buffer(prop->buffer_type);
973 if (buffer)
974 hfi->buffer_type = buffer;
975 else
976 return -EINVAL;
977 hfi->format = prop->format;
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -0800978 pkt->size += sizeof(u32) + sizeof(struct
979 hfi_uncompressed_format_select);
980 break;
981 }
982 case HAL_PARAM_UNCOMPRESSED_PLANE_ACTUAL_CONSTRAINTS_INFO:
983 break;
984 case HAL_PARAM_UNCOMPRESSED_PLANE_ACTUAL_INFO:
985 break;
986 case HAL_PARAM_EXTRA_DATA_HEADER_CONFIG:
987 break;
988 case HAL_PARAM_FRAME_SIZE:
989 {
Ashray Kulkarnife72c452012-05-29 19:52:00 -0700990 u32 buffer;
991 struct hfi_frame_size *hfi;
992 struct hal_frame_size *prop = (struct hal_frame_size *) pdata;
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -0800993 pkt->rg_property_data[0] = HFI_PROPERTY_PARAM_FRAME_SIZE;
Ashray Kulkarnife72c452012-05-29 19:52:00 -0700994 hfi = (struct hfi_frame_size *) &pkt->rg_property_data[1];
995 buffer = get_hfi_buffer(prop->buffer_type);
996 if (buffer)
997 hfi->buffer_type = buffer;
998 else
999 return -EINVAL;
1000 hfi->height = prop->height;
1001 hfi->width = prop->width;
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08001002 pkt->size += sizeof(u32) + sizeof(struct hfi_frame_size);
1003 break;
1004 }
1005 case HAL_CONFIG_REALTIME:
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08001006 {
Ashray Kulkarni1ccbc912012-03-23 16:26:52 -07001007 struct hfi_enable *hfi;
1008 pkt->rg_property_data[0] = HFI_PROPERTY_CONFIG_REALTIME;
1009 hfi = (struct hfi_enable *) &pkt->rg_property_data[1];
Ashray Kulkarnife72c452012-05-29 19:52:00 -07001010 hfi->enable = ((struct hfi_enable *) pdata)->enable;
1011 pkt->size += sizeof(u32) * 2;
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08001012 break;
1013 }
Ashray Kulkarni1ccbc912012-03-23 16:26:52 -07001014 case HAL_PARAM_BUFFER_COUNT_ACTUAL:
1015 {
Ashray Kulkarnife72c452012-05-29 19:52:00 -07001016 u32 buffer;
Ashray Kulkarni1ccbc912012-03-23 16:26:52 -07001017 struct hfi_buffer_count_actual *hfi;
Ashray Kulkarnife72c452012-05-29 19:52:00 -07001018 struct hal_buffer_count_actual *prop =
1019 (struct hal_buffer_count_actual *) pdata;
Ashray Kulkarni1ccbc912012-03-23 16:26:52 -07001020 pkt->rg_property_data[0] =
1021 HFI_PROPERTY_PARAM_BUFFER_COUNT_ACTUAL;
1022 hfi = (struct hfi_buffer_count_actual *)
1023 &pkt->rg_property_data[1];
Ashray Kulkarnife72c452012-05-29 19:52:00 -07001024 hfi->buffer_count_actual = prop->buffer_count_actual;
1025 buffer = get_hfi_buffer(prop->buffer_type);
1026 if (buffer)
1027 hfi->buffer_type = buffer;
1028 else
1029 return -EINVAL;
Ashray Kulkarni1ccbc912012-03-23 16:26:52 -07001030 pkt->size += sizeof(u32) + sizeof(struct
1031 hfi_buffer_count_actual);
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08001032 break;
Ashray Kulkarni1ccbc912012-03-23 16:26:52 -07001033 }
1034 case HAL_PARAM_NAL_STREAM_FORMAT_SELECT:
1035 {
Ashray Kulkarnife72c452012-05-29 19:52:00 -07001036 struct hal_nal_stream_format_supported *prop =
1037 (struct hal_nal_stream_format_supported *)pdata;
Ashray Kulkarni1ccbc912012-03-23 16:26:52 -07001038 pkt->rg_property_data[0] =
1039 HFI_PROPERTY_PARAM_NAL_STREAM_FORMAT_SELECT;
Blaine Dietrichf1a7cff2012-07-23 12:14:18 -07001040 dprintk(VIDC_DBG, "data is :%d",
Ashray Kulkarnife72c452012-05-29 19:52:00 -07001041 prop->nal_stream_format_supported);
1042 switch (prop->nal_stream_format_supported) {
1043 case HAL_NAL_FORMAT_STARTCODES:
1044 pkt->rg_property_data[1] =
1045 HFI_NAL_FORMAT_STARTCODES;
1046 break;
1047 case HAL_NAL_FORMAT_ONE_NAL_PER_BUFFER:
1048 pkt->rg_property_data[1] =
1049 HFI_NAL_FORMAT_ONE_NAL_PER_BUFFER;
1050 break;
1051 case HAL_NAL_FORMAT_ONE_BYTE_LENGTH:
1052 pkt->rg_property_data[1] =
1053 HFI_NAL_FORMAT_ONE_BYTE_LENGTH;
1054 break;
1055 case HAL_NAL_FORMAT_TWO_BYTE_LENGTH:
1056 pkt->rg_property_data[1] =
1057 HFI_NAL_FORMAT_TWO_BYTE_LENGTH;
1058 break;
1059 case HAL_NAL_FORMAT_FOUR_BYTE_LENGTH:
1060 pkt->rg_property_data[1] =
1061 HFI_NAL_FORMAT_FOUR_BYTE_LENGTH;
1062 break;
1063 default:
Blaine Dietrichf1a7cff2012-07-23 12:14:18 -07001064 dprintk(VIDC_ERR, "Invalid nal format: 0x%x",
Ashray Kulkarnife72c452012-05-29 19:52:00 -07001065 prop->nal_stream_format_supported);
1066 break;
1067 }
1068 pkt->size += sizeof(u32) * 2;
Ashray Kulkarni1ccbc912012-03-23 16:26:52 -07001069 break;
1070 }
1071 case HAL_PARAM_VDEC_OUTPUT_ORDER:
1072 {
Ashray Kulkarnife72c452012-05-29 19:52:00 -07001073 int *data = (int *) pdata;
Ashray Kulkarni1ccbc912012-03-23 16:26:52 -07001074 pkt->rg_property_data[0] =
1075 HFI_PROPERTY_PARAM_VDEC_OUTPUT_ORDER;
Ashray Kulkarnife72c452012-05-29 19:52:00 -07001076 switch (*data) {
1077 case HAL_OUTPUT_ORDER_DECODE:
Ashray Kulkarni995fd272012-07-02 12:57:55 -07001078 pkt->rg_property_data[1] = HFI_OUTPUT_ORDER_DECODE;
Ashray Kulkarnife72c452012-05-29 19:52:00 -07001079 break;
1080 case HAL_OUTPUT_ORDER_DISPLAY:
Ashray Kulkarni995fd272012-07-02 12:57:55 -07001081 pkt->rg_property_data[1] = HFI_OUTPUT_ORDER_DISPLAY;
Ashray Kulkarnife72c452012-05-29 19:52:00 -07001082 break;
1083 default:
Blaine Dietrichf1a7cff2012-07-23 12:14:18 -07001084 dprintk(VIDC_ERR, "invalid output order: 0x%x",
Ashray Kulkarnife72c452012-05-29 19:52:00 -07001085 *data);
1086 break;
1087 }
1088 pkt->size += sizeof(u32) * 2;
Ashray Kulkarni1ccbc912012-03-23 16:26:52 -07001089 break;
1090 }
1091 case HAL_PARAM_VDEC_PICTURE_TYPE_DECODE:
1092 {
1093 struct hfi_enable_picture *hfi;
1094 pkt->rg_property_data[0] =
1095 HFI_PROPERTY_PARAM_VDEC_PICTURE_TYPE_DECODE;
1096 hfi = (struct hfi_enable_picture *) &pkt->rg_property_data[1];
1097 hfi->picture_type = (u32) pdata;
Ashray Kulkarnife72c452012-05-29 19:52:00 -07001098 pkt->size += sizeof(u32) * 2;
Ashray Kulkarni1ccbc912012-03-23 16:26:52 -07001099 break;
1100 }
1101 case HAL_PARAM_VDEC_OUTPUT2_KEEP_ASPECT_RATIO:
1102 {
1103 struct hfi_enable *hfi;
1104 pkt->rg_property_data[0] =
1105 HFI_PROPERTY_PARAM_VDEC_OUTPUT2_KEEP_ASPECT_RATIO;
1106 hfi = (struct hfi_enable *) &pkt->rg_property_data[1];
Ashray Kulkarnife72c452012-05-29 19:52:00 -07001107 hfi->enable = ((struct hfi_enable *) pdata)->enable;
1108 pkt->size += sizeof(u32) * 2;
Ashray Kulkarni1ccbc912012-03-23 16:26:52 -07001109 break;
1110 }
1111 case HAL_CONFIG_VDEC_POST_LOOP_DEBLOCKER:
1112 {
1113 struct hfi_enable *hfi;
1114 pkt->rg_property_data[0] =
1115 HFI_PROPERTY_CONFIG_VDEC_POST_LOOP_DEBLOCKER;
1116 hfi = (struct hfi_enable *) &pkt->rg_property_data[1];
Ashray Kulkarnife72c452012-05-29 19:52:00 -07001117 hfi->enable = ((struct hfi_enable *) pdata)->enable;
1118 pkt->size += sizeof(u32) * 2;
Ashray Kulkarni1ccbc912012-03-23 16:26:52 -07001119 break;
1120 }
1121 case HAL_PARAM_VDEC_MULTI_STREAM:
1122 {
Ashray Kulkarnife72c452012-05-29 19:52:00 -07001123 u32 buffer;
Ashray Kulkarni1ccbc912012-03-23 16:26:52 -07001124 struct hfi_multi_stream *hfi;
Ashray Kulkarnife72c452012-05-29 19:52:00 -07001125 struct hal_multi_stream *prop =
1126 (struct hal_multi_stream *) pdata;
Ashray Kulkarni1ccbc912012-03-23 16:26:52 -07001127 pkt->rg_property_data[0] =
1128 HFI_PROPERTY_PARAM_VDEC_MULTI_STREAM;
1129 hfi = (struct hfi_multi_stream *) &pkt->rg_property_data[1];
Ashray Kulkarnife72c452012-05-29 19:52:00 -07001130 buffer = get_hfi_buffer(prop->buffer_type);
1131 if (buffer)
1132 hfi->buffer_type = buffer;
1133 else
1134 return -EINVAL;
1135 hfi->enable = prop->enable;
1136 hfi->width = prop->width;
1137 hfi->height = prop->height;
Ashray Kulkarni1ccbc912012-03-23 16:26:52 -07001138 pkt->size += sizeof(u32) + sizeof(struct hfi_multi_stream);
1139 break;
1140 }
1141 case HAL_PARAM_VDEC_DISPLAY_PICTURE_BUFFER_COUNT:
1142 {
Ashray Kulkarnife72c452012-05-29 19:52:00 -07001143 struct hfi_display_picture_buffer_count *hfi;
1144 struct hal_display_picture_buffer_count *prop =
1145 (struct hal_display_picture_buffer_count *) pdata;
Ashray Kulkarni1ccbc912012-03-23 16:26:52 -07001146 pkt->rg_property_data[0] =
1147 HFI_PROPERTY_PARAM_VDEC_DISPLAY_PICTURE_BUFFER_COUNT;
Ashray Kulkarnife72c452012-05-29 19:52:00 -07001148 hfi = (struct hfi_display_picture_buffer_count *)
Ashray Kulkarni1ccbc912012-03-23 16:26:52 -07001149 &pkt->rg_property_data[1];
Ashray Kulkarnife72c452012-05-29 19:52:00 -07001150 hfi->count = prop->count;
1151 hfi->enable = prop->enable;
Ashray Kulkarni1ccbc912012-03-23 16:26:52 -07001152 pkt->size += sizeof(u32) +
1153 sizeof(struct hfi_display_picture_buffer_count);
1154 break;
1155 }
1156 case HAL_PARAM_DIVX_FORMAT:
1157 {
Ashray Kulkarnife72c452012-05-29 19:52:00 -07001158 int *data = pdata;
Ashray Kulkarni1ccbc912012-03-23 16:26:52 -07001159 pkt->rg_property_data[0] = HFI_PROPERTY_PARAM_DIVX_FORMAT;
Ashray Kulkarnife72c452012-05-29 19:52:00 -07001160 switch (*data) {
1161 case HAL_DIVX_FORMAT_4:
1162 pkt->rg_property_data[1] = HFI_DIVX_FORMAT_4;
1163 break;
1164 case HAL_DIVX_FORMAT_5:
1165 pkt->rg_property_data[1] = HFI_DIVX_FORMAT_5;
1166 break;
1167 case HAL_DIVX_FORMAT_6:
1168 pkt->rg_property_data[1] = HFI_DIVX_FORMAT_6;
1169 break;
1170 default:
Blaine Dietrichf1a7cff2012-07-23 12:14:18 -07001171 dprintk(VIDC_ERR, "Invalid divx format: 0x%x", *data);
Ashray Kulkarnife72c452012-05-29 19:52:00 -07001172 break;
1173 }
1174 pkt->size += sizeof(u32) * 2;
Ashray Kulkarni1ccbc912012-03-23 16:26:52 -07001175 break;
1176 }
1177 case HAL_CONFIG_VDEC_MB_ERROR_MAP_REPORTING:
1178 {
1179 struct hfi_enable *hfi;
1180 pkt->rg_property_data[0] =
1181 HFI_PROPERTY_CONFIG_VDEC_MB_ERROR_MAP_REPORTING;
1182 hfi = (struct hfi_enable *) &pkt->rg_property_data[1];
Ashray Kulkarnife72c452012-05-29 19:52:00 -07001183 hfi->enable = ((struct hfi_enable *) pdata)->enable;
1184 pkt->size += sizeof(u32) * 2;
Ashray Kulkarni1ccbc912012-03-23 16:26:52 -07001185 break;
1186 }
1187 case HAL_PARAM_VDEC_CONTINUE_DATA_TRANSFER:
1188 {
Ashray Kulkarnife72c452012-05-29 19:52:00 -07001189 struct hfi_enable *hfi;
Ashray Kulkarni1ccbc912012-03-23 16:26:52 -07001190 pkt->rg_property_data[0] =
1191 HFI_PROPERTY_PARAM_VDEC_CONTINUE_DATA_TRANSFER;
Ashray Kulkarnife72c452012-05-29 19:52:00 -07001192 hfi = (struct hfi_enable *) &pkt->rg_property_data[1];
1193 hfi->enable = ((struct hfi_enable *) pdata)->enable;
1194 pkt->size += sizeof(u32) * 2;
Ashray Kulkarni1ccbc912012-03-23 16:26:52 -07001195 break;
1196 }
Praneeth Paladugu131aaac2012-10-16 17:30:22 -07001197 case HAL_PARAM_VDEC_SYNC_FRAME_DECODE:
1198 {
1199 struct hfi_enable *hfi;
1200 pkt->rg_property_data[0] =
1201 HFI_PROPERTY_PARAM_VDEC_THUMBNAIL_MODE;
1202 hfi = (struct hfi_enable *) &pkt->rg_property_data[1];
1203 hfi->enable = ((struct hfi_enable *) pdata)->enable;
1204 pkt->size += sizeof(u32) * 2;
1205 break;
1206 }
Ashray Kulkarni8c5f34f2012-09-14 17:13:38 -07001207 case HAL_PARAM_VENC_SYNC_FRAME_SEQUENCE_HEADER:
1208 {
1209 struct hfi_enable *hfi;
1210 pkt->rg_property_data[0] =
1211 HFI_PROPERTY_PARAM_VENC_SYNC_FRAME_SEQUENCE_HEADER;
1212 hfi = (struct hfi_enable *) &pkt->rg_property_data[1];
1213 hfi->enable = ((struct hfi_enable *) pdata)->enable;
1214 pkt->size += sizeof(u32) * 2;
1215 break;
1216 }
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08001217 case HAL_CONFIG_VENC_REQUEST_IFRAME:
Ashray Kulkarni1ccbc912012-03-23 16:26:52 -07001218 pkt->rg_property_data[0] =
Ashray Kulkarnife72c452012-05-29 19:52:00 -07001219 HFI_PROPERTY_CONFIG_VENC_REQUEST_SYNC_FRAME;
Praneeth Paladugu951c02d2012-07-11 12:19:42 -07001220 pkt->size += sizeof(u32);
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08001221 break;
1222 case HAL_PARAM_VENC_MPEG4_SHORT_HEADER:
1223 break;
1224 case HAL_PARAM_VENC_MPEG4_AC_PREDICTION:
1225 break;
1226 case HAL_CONFIG_VENC_TARGET_BITRATE:
Ashray Kulkarni1ccbc912012-03-23 16:26:52 -07001227 {
1228 struct hfi_bitrate *hfi;
1229 pkt->rg_property_data[0] =
1230 HFI_PROPERTY_CONFIG_VENC_TARGET_BITRATE;
1231 hfi = (struct hfi_bitrate *) &pkt->rg_property_data[1];
Ashray Kulkarnife72c452012-05-29 19:52:00 -07001232 hfi->bit_rate = ((struct hal_bitrate *)pdata)->bit_rate;
1233 pkt->size += sizeof(u32) * 2;
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08001234 break;
Ashray Kulkarni1ccbc912012-03-23 16:26:52 -07001235 }
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08001236 case HAL_PARAM_PROFILE_LEVEL_CURRENT:
1237 {
Ashray Kulkarnife72c452012-05-29 19:52:00 -07001238 struct hfi_profile_level *hfi;
1239 struct hal_profile_level *prop =
1240 (struct hal_profile_level *) pdata;
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08001241 pkt->rg_property_data[0] =
1242 HFI_PROPERTY_PARAM_PROFILE_LEVEL_CURRENT;
Ashray Kulkarnife72c452012-05-29 19:52:00 -07001243 hfi = (struct hfi_profile_level *)
1244 &pkt->rg_property_data[1];
1245 hfi->level = (u32) prop->level;
1246 hfi->profile = prop->profile;
1247 if (!hfi->profile)
1248 hfi->profile = HFI_H264_PROFILE_HIGH;
1249 if (!hfi->level)
1250 hfi->level = 1;
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08001251 pkt->size += sizeof(u32) + sizeof(struct hfi_profile_level);
1252 break;
1253 }
1254 case HAL_PARAM_VENC_H264_ENTROPY_CONTROL:
Ashray Kulkarni1ccbc912012-03-23 16:26:52 -07001255 {
1256 struct hfi_h264_entropy_control *hfi;
Ashray Kulkarnife72c452012-05-29 19:52:00 -07001257 struct hal_h264_entropy_control *prop =
1258 (struct hal_h264_entropy_control *) pdata;
Ashray Kulkarni1ccbc912012-03-23 16:26:52 -07001259 pkt->rg_property_data[0] =
1260 HFI_PROPERTY_PARAM_VENC_H264_ENTROPY_CONTROL;
1261 hfi = (struct hfi_h264_entropy_control *)
1262 &pkt->rg_property_data[1];
Ashray Kulkarnife72c452012-05-29 19:52:00 -07001263 switch (prop->entropy_mode) {
1264 case HAL_H264_ENTROPY_CAVLC:
1265 hfi->cabac_model = HFI_H264_ENTROPY_CAVLC;
1266 break;
1267 case HAL_H264_ENTROPY_CABAC:
1268 hfi->cabac_model = HFI_H264_ENTROPY_CABAC;
1269 switch (prop->cabac_model) {
1270 case HAL_H264_CABAC_MODEL_0:
1271 hfi->cabac_model = HFI_H264_CABAC_MODEL_0;
1272 break;
1273 case HAL_H264_CABAC_MODEL_1:
1274 hfi->cabac_model = HFI_H264_CABAC_MODEL_1;
1275 break;
1276 case HAL_H264_CABAC_MODEL_2:
1277 hfi->cabac_model = HFI_H264_CABAC_MODEL_2;
1278 break;
1279 default:
Blaine Dietrichf1a7cff2012-07-23 12:14:18 -07001280 dprintk(VIDC_ERR,
1281 "Invalid cabac model 0x%x",
1282 prop->entropy_mode);
Ashray Kulkarnife72c452012-05-29 19:52:00 -07001283 break;
1284 }
1285 break;
1286 default:
Blaine Dietrichf1a7cff2012-07-23 12:14:18 -07001287 dprintk(VIDC_ERR,
1288 "Invalid entropy selected: 0x%x",
Ashray Kulkarnife72c452012-05-29 19:52:00 -07001289 prop->cabac_model);
1290 break;
1291 }
Ashray Kulkarni1ccbc912012-03-23 16:26:52 -07001292 pkt->size += sizeof(u32) + sizeof(
1293 struct hfi_h264_entropy_control);
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08001294 break;
Ashray Kulkarni1ccbc912012-03-23 16:26:52 -07001295 }
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08001296 case HAL_PARAM_VENC_RATE_CONTROL:
Ashray Kulkarni1ccbc912012-03-23 16:26:52 -07001297 {
Ashray Kulkarnib6734502012-08-24 13:00:22 -07001298 u32 *rc;
Ashray Kulkarni1ccbc912012-03-23 16:26:52 -07001299 pkt->rg_property_data[0] =
1300 HFI_PROPERTY_PARAM_VENC_RATE_CONTROL;
Ashray Kulkarnib6734502012-08-24 13:00:22 -07001301 rc = (u32 *)pdata;
1302 switch ((enum hal_rate_control) *rc) {
Ashray Kulkarnife72c452012-05-29 19:52:00 -07001303 case HAL_RATE_CONTROL_OFF:
1304 pkt->rg_property_data[1] = HFI_RATE_CONTROL_OFF;
1305 break;
1306 case HAL_RATE_CONTROL_CBR_CFR:
1307 pkt->rg_property_data[1] = HFI_RATE_CONTROL_CBR_CFR;
1308 break;
1309 case HAL_RATE_CONTROL_CBR_VFR:
1310 pkt->rg_property_data[1] = HFI_RATE_CONTROL_CBR_VFR;
1311 break;
1312 case HAL_RATE_CONTROL_VBR_CFR:
1313 pkt->rg_property_data[1] = HFI_RATE_CONTROL_VBR_CFR;
1314 break;
1315 case HAL_RATE_CONTROL_VBR_VFR:
1316 pkt->rg_property_data[1] = HFI_RATE_CONTROL_VBR_VFR;
1317 break;
1318 default:
Blaine Dietrichf1a7cff2012-07-23 12:14:18 -07001319 dprintk(VIDC_ERR, "Invalid Rate control setting: 0x%x",
Ashray Kulkarnife72c452012-05-29 19:52:00 -07001320 (int) pdata);
1321 break;
1322 }
1323 pkt->size += sizeof(u32) * 2;
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08001324 break;
Ashray Kulkarni1ccbc912012-03-23 16:26:52 -07001325 }
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08001326 case HAL_PARAM_VENC_MPEG4_TIME_RESOLUTION:
Ashray Kulkarni1ccbc912012-03-23 16:26:52 -07001327 {
1328 struct hfi_mpeg4_time_resolution *hfi;
1329 pkt->rg_property_data[0] =
1330 HFI_PROPERTY_PARAM_VENC_MPEG4_TIME_RESOLUTION;
1331 hfi = (struct hfi_mpeg4_time_resolution *)
1332 &pkt->rg_property_data[1];
1333 hfi->time_increment_resolution =
1334 ((struct hal_mpeg4_time_resolution *)pdata)->
1335 time_increment_resolution;
Ashray Kulkarnife72c452012-05-29 19:52:00 -07001336 pkt->size += sizeof(u32) * 2;
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08001337 break;
Ashray Kulkarni1ccbc912012-03-23 16:26:52 -07001338 }
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08001339 case HAL_PARAM_VENC_MPEG4_HEADER_EXTENSION:
Ashray Kulkarni1ccbc912012-03-23 16:26:52 -07001340 {
1341 struct hfi_mpeg4_header_extension *hfi;
1342 pkt->rg_property_data[0] =
1343 HFI_PROPERTY_PARAM_VENC_MPEG4_HEADER_EXTENSION;
1344 hfi = (struct hfi_mpeg4_header_extension *)
Ashray Kulkarnife72c452012-05-29 19:52:00 -07001345 &pkt->rg_property_data[1];
Ashray Kulkarni1ccbc912012-03-23 16:26:52 -07001346 hfi->header_extension = (u32) pdata;
Ashray Kulkarnife72c452012-05-29 19:52:00 -07001347 pkt->size += sizeof(u32) * 2;
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08001348 break;
Ashray Kulkarni1ccbc912012-03-23 16:26:52 -07001349 }
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08001350 case HAL_PARAM_VENC_H264_DEBLOCK_CONTROL:
Ashray Kulkarni1ccbc912012-03-23 16:26:52 -07001351 {
1352 struct hfi_h264_db_control *hfi;
Ashray Kulkarnife72c452012-05-29 19:52:00 -07001353 struct hal_h264_db_control *prop =
1354 (struct hal_h264_db_control *) pdata;
Ashray Kulkarni1ccbc912012-03-23 16:26:52 -07001355 pkt->rg_property_data[0] =
1356 HFI_PROPERTY_PARAM_VENC_H264_DEBLOCK_CONTROL;
1357 hfi = (struct hfi_h264_db_control *) &pkt->rg_property_data[1];
Ashray Kulkarnife72c452012-05-29 19:52:00 -07001358 switch (prop->mode) {
1359 case HAL_H264_DB_MODE_DISABLE:
1360 hfi->mode = HFI_H264_DB_MODE_DISABLE;
1361 break;
1362 case HAL_H264_DB_MODE_SKIP_SLICE_BOUNDARY:
1363 hfi->mode = HFI_H264_DB_MODE_SKIP_SLICE_BOUNDARY;
1364 break;
1365 case HAL_H264_DB_MODE_ALL_BOUNDARY:
1366 hfi->mode = HFI_H264_DB_MODE_ALL_BOUNDARY;
1367 break;
1368 default:
Blaine Dietrichf1a7cff2012-07-23 12:14:18 -07001369 dprintk(VIDC_ERR, "Invalid deblocking mode: 0x%x",
Ashray Kulkarnife72c452012-05-29 19:52:00 -07001370 prop->mode);
1371 break;
1372 }
1373 hfi->slice_alpha_offset = prop->slice_alpha_offset;
1374 hfi->slice_beta_offset = prop->slice_beta_offset;
Ashray Kulkarni1ccbc912012-03-23 16:26:52 -07001375 pkt->size += sizeof(u32) +
1376 sizeof(struct hfi_h264_db_control);
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08001377 break;
Ashray Kulkarni1ccbc912012-03-23 16:26:52 -07001378 }
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08001379 case HAL_PARAM_VENC_SESSION_QP:
Ashray Kulkarni1ccbc912012-03-23 16:26:52 -07001380 {
1381 struct hfi_quantization *hfi;
1382 pkt->rg_property_data[0] =
1383 HFI_PROPERTY_PARAM_VENC_SESSION_QP;
1384 hfi = (struct hfi_quantization *) &pkt->rg_property_data[1];
1385 memcpy(hfi, (struct hfi_quantization *) pdata,
1386 sizeof(struct hfi_quantization));
1387 pkt->size += sizeof(u32) + sizeof(struct hfi_quantization);
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08001388 break;
Ashray Kulkarni1ccbc912012-03-23 16:26:52 -07001389 }
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08001390 case HAL_CONFIG_VENC_INTRA_PERIOD:
Ashray Kulkarni1ccbc912012-03-23 16:26:52 -07001391 {
1392 struct hfi_intra_period *hfi;
1393 pkt->rg_property_data[0] =
1394 HFI_PROPERTY_CONFIG_VENC_INTRA_PERIOD;
1395 hfi = (struct hfi_intra_period *) &pkt->rg_property_data[1];
1396 memcpy(hfi, (struct hfi_intra_period *) pdata,
1397 sizeof(struct hfi_intra_period));
1398 pkt->size += sizeof(u32) + sizeof(struct hfi_intra_period);
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08001399 break;
Ashray Kulkarni1ccbc912012-03-23 16:26:52 -07001400 }
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08001401 case HAL_CONFIG_VENC_IDR_PERIOD:
Ashray Kulkarni1ccbc912012-03-23 16:26:52 -07001402 {
1403 struct hfi_idr_period *hfi;
1404 pkt->rg_property_data[0] = HFI_PROPERTY_CONFIG_VENC_IDR_PERIOD;
1405 hfi = (struct hfi_idr_period *) &pkt->rg_property_data[1];
1406 hfi->idr_period = ((struct hfi_idr_period *) pdata)->idr_period;
Ashray Kulkarnife72c452012-05-29 19:52:00 -07001407 pkt->size += sizeof(u32) * 2;
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08001408 break;
Ashray Kulkarni1ccbc912012-03-23 16:26:52 -07001409 }
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08001410 case HAL_CONFIG_VPE_OPERATIONS:
1411 break;
1412 case HAL_PARAM_VENC_INTRA_REFRESH:
Ashray Kulkarni1ccbc912012-03-23 16:26:52 -07001413 {
1414 struct hfi_intra_refresh *hfi;
Ashray Kulkarnife72c452012-05-29 19:52:00 -07001415 struct hal_intra_refresh *prop =
1416 (struct hal_intra_refresh *) pdata;
Ashray Kulkarni1ccbc912012-03-23 16:26:52 -07001417 pkt->rg_property_data[0] =
1418 HFI_PROPERTY_PARAM_VENC_INTRA_REFRESH;
1419 hfi = (struct hfi_intra_refresh *) &pkt->rg_property_data[1];
Ashray Kulkarnife72c452012-05-29 19:52:00 -07001420 switch (prop->mode) {
1421 case HAL_INTRA_REFRESH_NONE:
1422 hfi->mode = HFI_INTRA_REFRESH_NONE;
1423 break;
1424 case HAL_INTRA_REFRESH_ADAPTIVE:
1425 hfi->mode = HFI_INTRA_REFRESH_ADAPTIVE;
1426 break;
1427 case HAL_INTRA_REFRESH_CYCLIC:
1428 hfi->mode = HFI_INTRA_REFRESH_CYCLIC;
1429 break;
1430 case HAL_INTRA_REFRESH_CYCLIC_ADAPTIVE:
1431 hfi->mode = HFI_INTRA_REFRESH_CYCLIC_ADAPTIVE;
1432 break;
1433 case HAL_INTRA_REFRESH_RANDOM:
1434 hfi->mode = HFI_INTRA_REFRESH_RANDOM;
1435 break;
1436 default:
Blaine Dietrichf1a7cff2012-07-23 12:14:18 -07001437 dprintk(VIDC_ERR, "Invalid intra refresh setting: 0x%x",
Ashray Kulkarnife72c452012-05-29 19:52:00 -07001438 prop->mode);
1439 break;
1440 }
1441 hfi->air_mbs = prop->air_mbs;
1442 hfi->air_ref = prop->air_ref;
1443 hfi->cir_mbs = prop->cir_mbs;
Ashray Kulkarni1ccbc912012-03-23 16:26:52 -07001444 pkt->size += sizeof(u32) + sizeof(struct hfi_intra_refresh);
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08001445 break;
Ashray Kulkarni1ccbc912012-03-23 16:26:52 -07001446 }
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08001447 case HAL_PARAM_VENC_MULTI_SLICE_CONTROL:
Ashray Kulkarni1ccbc912012-03-23 16:26:52 -07001448 {
1449 struct hfi_multi_slice_control *hfi;
Ashray Kulkarnife72c452012-05-29 19:52:00 -07001450 struct hal_multi_slice_control *prop =
1451 (struct hal_multi_slice_control *) pdata;
Ashray Kulkarni1ccbc912012-03-23 16:26:52 -07001452 pkt->rg_property_data[0] =
1453 HFI_PROPERTY_PARAM_VENC_MULTI_SLICE_CONTROL;
1454 hfi = (struct hfi_multi_slice_control *)
Ashray Kulkarnife72c452012-05-29 19:52:00 -07001455 &pkt->rg_property_data[1];
1456 switch (prop->multi_slice) {
1457 case HAL_MULTI_SLICE_OFF:
1458 hfi->multi_slice = HFI_MULTI_SLICE_OFF;
1459 break;
1460 case HAL_MULTI_SLICE_GOB:
1461 hfi->multi_slice = HFI_MULTI_SLICE_GOB;
1462 break;
1463 case HAL_MULTI_SLICE_BY_MB_COUNT:
1464 hfi->multi_slice = HFI_MULTI_SLICE_BY_MB_COUNT;
1465 break;
1466 case HAL_MULTI_SLICE_BY_BYTE_COUNT:
1467 hfi->multi_slice = HFI_MULTI_SLICE_BY_BYTE_COUNT;
1468 break;
1469 default:
Blaine Dietrichf1a7cff2012-07-23 12:14:18 -07001470 dprintk(VIDC_ERR, "Invalid slice settings: 0x%x",
Ashray Kulkarnife72c452012-05-29 19:52:00 -07001471 prop->multi_slice);
1472 break;
1473 }
Ashray Kulkarni6a8803f2012-10-09 18:41:49 -07001474 hfi->slice_size = prop->slice_size;
Ashray Kulkarni1ccbc912012-03-23 16:26:52 -07001475 pkt->size += sizeof(u32) + sizeof(struct
Ashray Kulkarnife72c452012-05-29 19:52:00 -07001476 hfi_multi_slice_control);
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08001477 break;
Ashray Kulkarni1ccbc912012-03-23 16:26:52 -07001478 }
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08001479 case HAL_CONFIG_VPE_DEINTERLACE:
1480 break;
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08001481 /* FOLLOWING PROPERTIES ARE NOT IMPLEMENTED IN CORE YET */
1482 case HAL_CONFIG_BUFFER_REQUIREMENTS:
1483 case HAL_CONFIG_PRIORITY:
1484 case HAL_CONFIG_BATCH_INFO:
1485 case HAL_PARAM_METADATA_PASS_THROUGH:
1486 case HAL_SYS_IDLE_INDICATOR:
1487 case HAL_PARAM_UNCOMPRESSED_FORMAT_SUPPORTED:
1488 case HAL_PARAM_INTERLACE_FORMAT_SUPPORTED:
1489 case HAL_PARAM_CHROMA_SITE:
1490 case HAL_PARAM_PROPERTIES_SUPPORTED:
1491 case HAL_PARAM_PROFILE_LEVEL_SUPPORTED:
1492 case HAL_PARAM_CAPABILITY_SUPPORTED:
1493 case HAL_PARAM_NAL_STREAM_FORMAT_SUPPORTED:
1494 case HAL_PARAM_MULTI_VIEW_FORMAT:
1495 case HAL_PARAM_MAX_SEQUENCE_HEADER_SIZE:
1496 case HAL_PARAM_CODEC_SUPPORTED:
1497 case HAL_PARAM_VDEC_MULTI_VIEW_SELECT:
1498 case HAL_PARAM_VDEC_MB_QUANTIZATION:
1499 case HAL_PARAM_VDEC_NUM_CONCEALED_MB:
1500 case HAL_PARAM_VDEC_H264_ENTROPY_SWITCHING:
1501 case HAL_PARAM_VENC_SLICE_DELIVERY_MODE:
1502 case HAL_PARAM_VENC_MPEG4_DATA_PARTITIONING:
1503
1504 case HAL_CONFIG_BUFFER_COUNT_ACTUAL:
1505 case HAL_CONFIG_VDEC_MULTI_STREAM:
1506 case HAL_PARAM_VENC_MULTI_SLICE_INFO:
1507 case HAL_CONFIG_VENC_TIMESTAMP_SCALE:
1508 case HAL_PARAM_VENC_LOW_LATENCY:
1509 default:
Blaine Dietrichf1a7cff2012-07-23 12:14:18 -07001510 dprintk(VIDC_INFO, "DEFAULT: Calling 0x%x", ptype);
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08001511 break;
1512 }
1513 if (vidc_hal_iface_cmdq_write(session->device, pkt))
1514 return -ENOTEMPTY;
1515 return 0;
1516}
1517
1518int vidc_hal_session_get_property(void *sess,
1519 enum hal_property ptype, void *pdata)
1520{
1521 struct hal_session *session;
1522
1523 if (!sess || !pdata) {
Blaine Dietrichf1a7cff2012-07-23 12:14:18 -07001524 dprintk(VIDC_ERR, "Invalid Params in ");
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08001525 return -EINVAL;
1526 } else {
1527 session = sess;
1528 }
Blaine Dietrichf1a7cff2012-07-23 12:14:18 -07001529 dprintk(VIDC_INFO, "IN func: , with property id: %d", ptype);
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08001530
1531 switch (ptype) {
1532 case HAL_CONFIG_FRAME_RATE:
1533 break;
1534 case HAL_PARAM_UNCOMPRESSED_FORMAT_SELECT:
1535 break;
1536 case HAL_PARAM_UNCOMPRESSED_PLANE_ACTUAL_CONSTRAINTS_INFO:
1537 break;
1538 case HAL_PARAM_UNCOMPRESSED_PLANE_ACTUAL_INFO:
1539 break;
1540 case HAL_PARAM_EXTRA_DATA_HEADER_CONFIG:
1541 break;
1542 case HAL_PARAM_FRAME_SIZE:
1543 break;
1544 case HAL_CONFIG_REALTIME:
1545 break;
1546 case HAL_PARAM_BUFFER_COUNT_ACTUAL:
1547 break;
1548 case HAL_PARAM_NAL_STREAM_FORMAT_SELECT:
1549 break;
1550 case HAL_PARAM_VDEC_OUTPUT_ORDER:
1551 break;
1552 case HAL_PARAM_VDEC_PICTURE_TYPE_DECODE:
1553 break;
1554 case HAL_PARAM_VDEC_OUTPUT2_KEEP_ASPECT_RATIO:
1555 break;
1556 case HAL_CONFIG_VDEC_POST_LOOP_DEBLOCKER:
1557 break;
1558 case HAL_PARAM_VDEC_MULTI_STREAM:
1559 break;
1560 case HAL_PARAM_VDEC_DISPLAY_PICTURE_BUFFER_COUNT:
1561 break;
1562 case HAL_PARAM_DIVX_FORMAT:
1563 break;
1564 case HAL_CONFIG_VDEC_MB_ERROR_MAP_REPORTING:
1565 break;
1566 case HAL_PARAM_VDEC_CONTINUE_DATA_TRANSFER:
1567 break;
1568 case HAL_CONFIG_VDEC_MB_ERROR_MAP:
1569 break;
1570 case HAL_CONFIG_VENC_REQUEST_IFRAME:
1571 break;
1572 case HAL_PARAM_VENC_MPEG4_SHORT_HEADER:
1573 break;
1574 case HAL_PARAM_VENC_MPEG4_AC_PREDICTION:
1575 break;
1576 case HAL_CONFIG_VENC_TARGET_BITRATE:
1577 break;
1578 case HAL_PARAM_PROFILE_LEVEL_CURRENT:
1579 break;
1580 case HAL_PARAM_VENC_H264_ENTROPY_CONTROL:
1581 break;
1582 case HAL_PARAM_VENC_RATE_CONTROL:
1583 break;
1584 case HAL_PARAM_VENC_MPEG4_TIME_RESOLUTION:
1585 break;
1586 case HAL_PARAM_VENC_MPEG4_HEADER_EXTENSION:
1587 break;
1588 case HAL_PARAM_VENC_H264_DEBLOCK_CONTROL:
1589 break;
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08001590 case HAL_PARAM_VENC_SESSION_QP:
1591 break;
1592 case HAL_CONFIG_VENC_INTRA_PERIOD:
1593 break;
1594 case HAL_CONFIG_VENC_IDR_PERIOD:
1595 break;
1596 case HAL_CONFIG_VPE_OPERATIONS:
1597 break;
1598 case HAL_PARAM_VENC_INTRA_REFRESH:
1599 break;
1600 case HAL_PARAM_VENC_MULTI_SLICE_CONTROL:
1601 break;
1602 case HAL_CONFIG_VPE_DEINTERLACE:
1603 break;
1604 case HAL_SYS_DEBUG_CONFIG:
1605 break;
1606 /*FOLLOWING PROPERTIES ARE NOT IMPLEMENTED IN CORE YET*/
1607 case HAL_CONFIG_BUFFER_REQUIREMENTS:
1608 case HAL_CONFIG_PRIORITY:
1609 case HAL_CONFIG_BATCH_INFO:
1610 case HAL_PARAM_METADATA_PASS_THROUGH:
1611 case HAL_SYS_IDLE_INDICATOR:
1612 case HAL_PARAM_UNCOMPRESSED_FORMAT_SUPPORTED:
1613 case HAL_PARAM_INTERLACE_FORMAT_SUPPORTED:
1614 case HAL_PARAM_CHROMA_SITE:
1615 case HAL_PARAM_PROPERTIES_SUPPORTED:
1616 case HAL_PARAM_PROFILE_LEVEL_SUPPORTED:
1617 case HAL_PARAM_CAPABILITY_SUPPORTED:
1618 case HAL_PARAM_NAL_STREAM_FORMAT_SUPPORTED:
1619 case HAL_PARAM_MULTI_VIEW_FORMAT:
1620 case HAL_PARAM_MAX_SEQUENCE_HEADER_SIZE:
1621 case HAL_PARAM_CODEC_SUPPORTED:
1622 case HAL_PARAM_VDEC_MULTI_VIEW_SELECT:
1623 case HAL_PARAM_VDEC_MB_QUANTIZATION:
1624 case HAL_PARAM_VDEC_NUM_CONCEALED_MB:
1625 case HAL_PARAM_VDEC_H264_ENTROPY_SWITCHING:
1626 case HAL_PARAM_VENC_SLICE_DELIVERY_MODE:
1627 case HAL_PARAM_VENC_MPEG4_DATA_PARTITIONING:
1628
1629 case HAL_CONFIG_BUFFER_COUNT_ACTUAL:
1630 case HAL_CONFIG_VDEC_MULTI_STREAM:
1631 case HAL_PARAM_VENC_MULTI_SLICE_INFO:
1632 case HAL_CONFIG_VENC_TIMESTAMP_SCALE:
1633 case HAL_PARAM_VENC_LOW_LATENCY:
1634 default:
Blaine Dietrichf1a7cff2012-07-23 12:14:18 -07001635 dprintk(VIDC_INFO, "DEFAULT: Calling 0x%x", ptype);
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08001636 break;
1637 }
1638 return 0;
1639}
1640
1641void *vidc_hal_session_init(void *device, u32 session_id,
1642 enum hal_domain session_type, enum hal_video_codec codec_type)
1643{
1644 struct hfi_cmd_sys_session_init_packet pkt;
1645 struct hal_session *new_session;
1646 struct hal_device *dev;
1647
1648 if (device) {
1649 dev = device;
1650 } else {
Ashray Kulkarni000b3822012-10-11 18:20:58 -07001651 dprintk(VIDC_ERR, "invalid device");
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08001652 return NULL;
1653 }
1654
1655 new_session = (struct hal_session *)
1656 kzalloc(sizeof(struct hal_session), GFP_KERNEL);
1657 new_session->session_id = (u32) session_id;
1658 if (session_type == 1)
1659 new_session->is_decoder = 0;
1660 else if (session_type == 2)
1661 new_session->is_decoder = 1;
1662 new_session->device = dev;
1663 list_add_tail(&new_session->list, &dev->sess_head);
1664 pkt.size = sizeof(struct hfi_cmd_sys_session_init_packet);
Ashray Kulkarnife72c452012-05-29 19:52:00 -07001665 pkt.packet_type = HFI_CMD_SYS_SESSION_INIT;
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08001666 pkt.session_id = (u32) new_session;
1667 pkt.session_domain = session_type;
1668 pkt.session_codec = codec_type;
1669 if (vidc_hal_iface_cmdq_write(dev, &pkt))
1670 return NULL;
Ashray Kulkarnicde78522012-06-28 18:14:50 -07001671 if (vidc_hal_sys_set_debug(dev, msm_fw_debug))
1672 dprintk(VIDC_ERR, "Setting fw_debug msg ON failed");
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08001673 return (void *) new_session;
1674}
1675
1676static int vidc_hal_send_session_cmd(void *session_id,
Ashray Kulkarnife72c452012-05-29 19:52:00 -07001677 int pkt_type)
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08001678{
1679 struct vidc_hal_session_cmd_pkt pkt;
1680 int rc = 0;
1681 struct hal_session *session;
1682
1683 if (session_id) {
1684 session = session_id;
1685 } else {
Ashray Kulkarni000b3822012-10-11 18:20:58 -07001686 dprintk(VIDC_ERR, "invalid session");
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08001687 return -ENODEV;
1688 }
1689
1690 pkt.size = sizeof(struct vidc_hal_session_cmd_pkt);
1691 pkt.packet_type = pkt_type;
1692 pkt.session_id = (u32) session;
1693
1694 if (vidc_hal_iface_cmdq_write(session->device, &pkt))
1695 rc = -ENOTEMPTY;
1696 return rc;
1697}
1698
1699int vidc_hal_session_end(void *session)
1700{
1701 return vidc_hal_send_session_cmd(session,
1702 HFI_CMD_SYS_SESSION_END);
1703}
1704
1705int vidc_hal_session_abort(void *session)
1706{
1707 return vidc_hal_send_session_cmd(session,
1708 HFI_CMD_SYS_SESSION_ABORT);
1709}
1710
1711int vidc_hal_session_set_buffers(void *sess,
1712 struct vidc_buffer_addr_info *buffer_info)
1713{
Ashray Kulkarnife72c452012-05-29 19:52:00 -07001714 u32 buffer;
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08001715 struct hfi_cmd_session_set_buffers_packet *pkt;
1716 u8 packet[VIDC_IFACEQ_VAR_LARGE_PKT_SIZE];
1717 int rc = 0;
1718 u16 i;
1719 struct hal_session *session;
1720
1721 if (!sess || !buffer_info) {
Ashray Kulkarni000b3822012-10-11 18:20:58 -07001722 dprintk(VIDC_ERR, "Invalid Params");
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08001723 return -EINVAL;
1724 } else {
1725 session = sess;
1726 }
1727
1728 if (buffer_info->buffer_type == HAL_BUFFER_INPUT)
1729 return 0;
1730
1731 pkt = (struct hfi_cmd_session_set_buffers_packet *)packet;
1732
1733 pkt->size = sizeof(struct hfi_cmd_session_set_buffers_packet) +
1734 ((buffer_info->num_buffers - 1) * sizeof(u32));
1735 pkt->packet_type = HFI_CMD_SESSION_SET_BUFFERS;
1736 pkt->session_id = (u32) session;
1737 pkt->buffer_mode = HFI_BUFFER_MODE_STATIC;
1738 pkt->buffer_size = buffer_info->buffer_size;
1739 pkt->min_buffer_size = buffer_info->buffer_size;
1740 pkt->num_buffers = buffer_info->num_buffers;
1741
1742 if ((buffer_info->buffer_type == HAL_BUFFER_OUTPUT) ||
1743 (buffer_info->buffer_type == HAL_BUFFER_OUTPUT2)) {
1744 struct hfi_buffer_info *buff;
Ashray Kulkarnife72c452012-05-29 19:52:00 -07001745 pkt->extra_data_size = buffer_info->extradata_size;
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08001746 pkt->size = sizeof(struct hfi_cmd_session_set_buffers_packet) -
1747 sizeof(u32) + ((buffer_info->num_buffers) *
1748 sizeof(struct hfi_buffer_info));
1749 buff = (struct hfi_buffer_info *) pkt->rg_buffer_info;
1750 for (i = 0; i < pkt->num_buffers; i++) {
1751 buff->buffer_addr =
1752 buffer_info->align_device_addr;
Ashray Kulkarnife72c452012-05-29 19:52:00 -07001753 buff->extra_data_addr =
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08001754 buffer_info->extradata_addr;
1755 }
1756 } else {
Ashray Kulkarnife72c452012-05-29 19:52:00 -07001757 pkt->extra_data_size = 0;
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08001758 pkt->size = sizeof(struct hfi_cmd_session_set_buffers_packet) +
1759 ((buffer_info->num_buffers - 1) * sizeof(u32));
1760 for (i = 0; i < pkt->num_buffers; i++)
1761 pkt->rg_buffer_info[i] =
1762 buffer_info->align_device_addr;
1763 }
Ashray Kulkarnife72c452012-05-29 19:52:00 -07001764 buffer = get_hfi_buffer(buffer_info->buffer_type);
1765 if (buffer)
1766 pkt->buffer_type = buffer;
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08001767 else
Ashray Kulkarnife72c452012-05-29 19:52:00 -07001768 return -EINVAL;
Blaine Dietrichf1a7cff2012-07-23 12:14:18 -07001769 dprintk(VIDC_INFO, "set buffers: 0x%x", buffer_info->buffer_type);
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08001770 if (vidc_hal_iface_cmdq_write(session->device, pkt))
1771 rc = -ENOTEMPTY;
1772 return rc;
1773}
1774
1775int vidc_hal_session_release_buffers(void *sess,
1776 struct vidc_buffer_addr_info *buffer_info)
1777{
Ashray Kulkarnife72c452012-05-29 19:52:00 -07001778 u32 buffer;
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08001779 struct hfi_cmd_session_release_buffer_packet *pkt;
1780 u8 packet[VIDC_IFACEQ_VAR_LARGE_PKT_SIZE];
1781 int rc = 0;
1782 u32 i;
1783 struct hal_session *session;
1784
1785 if (!sess || !buffer_info) {
Ashray Kulkarni000b3822012-10-11 18:20:58 -07001786 dprintk(VIDC_ERR, "Invalid Params");
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08001787 return -EINVAL;
1788 } else {
1789 session = sess;
1790 }
1791
1792 if (buffer_info->buffer_type == HAL_BUFFER_INPUT)
1793 return 0;
1794
1795 pkt = (struct hfi_cmd_session_release_buffer_packet *) packet;
1796 pkt->size = sizeof(struct hfi_cmd_session_release_buffer_packet) +
1797 ((buffer_info->num_buffers - 1) * sizeof(u32));
1798 pkt->packet_type = HFI_CMD_SESSION_RELEASE_BUFFERS;
1799 pkt->session_id = (u32) session;
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08001800 pkt->buffer_size = buffer_info->buffer_size;
1801 pkt->num_buffers = buffer_info->num_buffers;
1802
1803 if ((buffer_info->buffer_type == HAL_BUFFER_OUTPUT) ||
1804 (buffer_info->buffer_type == HAL_BUFFER_OUTPUT2)) {
1805 struct hfi_buffer_info *buff;
1806 buff = (struct hfi_buffer_info *) pkt->rg_buffer_info;
1807 for (i = 0; i < pkt->num_buffers; i++) {
1808 buff->buffer_addr =
1809 buffer_info->align_device_addr;
Ashray Kulkarnife72c452012-05-29 19:52:00 -07001810 buff->extra_data_addr =
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08001811 buffer_info->extradata_addr;
1812 }
Ashray Kulkarnife72c452012-05-29 19:52:00 -07001813 pkt->extra_data_size = buffer_info->extradata_size;
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08001814 pkt->size = sizeof(struct hfi_cmd_session_set_buffers_packet) -
1815 sizeof(u32) + ((buffer_info->num_buffers) *
1816 sizeof(struct hfi_buffer_info));
1817 } else {
1818 for (i = 0; i < pkt->num_buffers; i++)
1819 pkt->rg_buffer_info[i] =
1820 buffer_info->align_device_addr;
Ashray Kulkarnife72c452012-05-29 19:52:00 -07001821 pkt->extra_data_size = 0;
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08001822 pkt->size = sizeof(struct hfi_cmd_session_set_buffers_packet) +
1823 ((buffer_info->num_buffers - 1) * sizeof(u32));
1824 }
Ashray Kulkarnife72c452012-05-29 19:52:00 -07001825 buffer = get_hfi_buffer(buffer_info->buffer_type);
1826 if (buffer)
1827 pkt->buffer_type = buffer;
1828 else
1829 return -EINVAL;
Blaine Dietrichf1a7cff2012-07-23 12:14:18 -07001830 dprintk(VIDC_INFO, "Release buffers: 0x%x", buffer_info->buffer_type);
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08001831 if (vidc_hal_iface_cmdq_write(session->device, pkt))
1832 rc = -ENOTEMPTY;
1833 return rc;
1834}
1835
1836int vidc_hal_session_load_res(void *sess)
1837{
1838 return vidc_hal_send_session_cmd(sess,
1839 HFI_CMD_SESSION_LOAD_RESOURCES);
1840}
1841
1842int vidc_hal_session_release_res(void *sess)
1843{
1844 return vidc_hal_send_session_cmd(sess,
1845 HFI_CMD_SESSION_RELEASE_RESOURCES);
1846}
1847
1848int vidc_hal_session_start(void *sess)
1849{
1850 return vidc_hal_send_session_cmd(sess,
1851 HFI_CMD_SESSION_START);
1852}
1853
1854int vidc_hal_session_stop(void *sess)
1855{
1856 return vidc_hal_send_session_cmd(sess,
1857 HFI_CMD_SESSION_STOP);
1858}
1859
1860int vidc_hal_session_suspend(void *sess)
1861{
1862 return vidc_hal_send_session_cmd(sess,
1863 HFI_CMD_SESSION_SUSPEND);
1864}
1865
1866int vidc_hal_session_resume(void *sess)
1867{
1868 return vidc_hal_send_session_cmd(sess,
1869 HFI_CMD_SESSION_RESUME);
1870}
1871
1872int vidc_hal_session_etb(void *sess, struct vidc_frame_data *input_frame)
1873{
1874 int rc = 0;
1875 struct hal_session *session;
1876
1877 if (!sess || !input_frame) {
Ashray Kulkarni000b3822012-10-11 18:20:58 -07001878 dprintk(VIDC_ERR, "Invalid Params");
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08001879 return -EINVAL;
1880 } else {
1881 session = sess;
1882 }
1883
1884 if (session->is_decoder) {
1885 struct hfi_cmd_session_empty_buffer_compressed_packet pkt;
1886 pkt.size = sizeof(
1887 struct hfi_cmd_session_empty_buffer_compressed_packet);
1888 pkt.packet_type = HFI_CMD_SESSION_EMPTY_BUFFER;
1889 pkt.session_id = (u32) session;
Ashray Kulkarnife72c452012-05-29 19:52:00 -07001890 pkt.time_stamp_hi = (int) (((u64)input_frame->timestamp) >> 32);
1891 pkt.time_stamp_lo = (int) input_frame->timestamp;
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08001892 pkt.flags = input_frame->flags;
1893 pkt.mark_target = input_frame->mark_target;
1894 pkt.mark_data = input_frame->mark_data;
1895 pkt.offset = input_frame->offset;
1896 pkt.alloc_len = input_frame->alloc_len;
1897 pkt.filled_len = input_frame->filled_len;
1898 pkt.input_tag = input_frame->clnt_data;
1899 pkt.packet_buffer = (u8 *) input_frame->device_addr;
Blaine Dietrichf1a7cff2012-07-23 12:14:18 -07001900 dprintk(VIDC_DBG, "Q DECODER INPUT BUFFER");
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08001901 if (vidc_hal_iface_cmdq_write(session->device, &pkt))
1902 rc = -ENOTEMPTY;
1903 } else {
1904 struct hfi_cmd_session_empty_buffer_uncompressed_plane0_packet
1905 pkt;
1906 pkt.size = sizeof(struct
1907 hfi_cmd_session_empty_buffer_uncompressed_plane0_packet);
Ashray Kulkarnife72c452012-05-29 19:52:00 -07001908 pkt.packet_type = HFI_CMD_SESSION_EMPTY_BUFFER;
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08001909 pkt.session_id = (u32) session;
1910 pkt.view_id = 0;
Ashray Kulkarnife72c452012-05-29 19:52:00 -07001911 pkt.time_stamp_hi = (u32) (((u64)input_frame->timestamp) >> 32);
1912 pkt.time_stamp_lo = (u32) input_frame->timestamp;
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08001913 pkt.flags = input_frame->flags;
1914 pkt.mark_target = input_frame->mark_target;
1915 pkt.mark_data = input_frame->mark_data;
1916 pkt.offset = input_frame->offset;
1917 pkt.alloc_len = input_frame->alloc_len;
1918 pkt.filled_len = input_frame->filled_len;
1919 pkt.input_tag = input_frame->clnt_data;
1920 pkt.packet_buffer = (u8 *) input_frame->device_addr;
Blaine Dietrichf1a7cff2012-07-23 12:14:18 -07001921 dprintk(VIDC_DBG, "Q ENCODER INPUT BUFFER");
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08001922 if (vidc_hal_iface_cmdq_write(session->device, &pkt))
1923 rc = -ENOTEMPTY;
1924 }
1925 return rc;
1926}
1927
1928int vidc_hal_session_ftb(void *sess,
1929 struct vidc_frame_data *output_frame)
1930{
1931 struct hfi_cmd_session_fill_buffer_packet pkt;
1932 int rc = 0;
1933 struct hal_session *session;
1934
1935 if (!sess || !output_frame) {
Ashray Kulkarni000b3822012-10-11 18:20:58 -07001936 dprintk(VIDC_ERR, "Invalid Params");
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08001937 return -EINVAL;
1938 } else {
1939 session = sess;
1940 }
1941
1942 pkt.size = sizeof(struct hfi_cmd_session_fill_buffer_packet);
1943 pkt.packet_type = HFI_CMD_SESSION_FILL_BUFFER;
1944 pkt.session_id = (u32) session;
1945 if (output_frame->buffer_type == HAL_BUFFER_OUTPUT)
1946 pkt.stream_id = 0;
1947 else if (output_frame->buffer_type == HAL_BUFFER_OUTPUT2)
1948 pkt.stream_id = 1;
1949 pkt.packet_buffer = (u8 *) output_frame->device_addr;
1950 pkt.extra_data_buffer =
1951 (u8 *) output_frame->extradata_addr;
1952
Blaine Dietrichf1a7cff2012-07-23 12:14:18 -07001953 dprintk(VIDC_INFO, "### Q OUTPUT BUFFER ###");
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08001954 if (vidc_hal_iface_cmdq_write(session->device, &pkt))
1955 rc = -ENOTEMPTY;
1956 return rc;
1957}
1958
1959int vidc_hal_session_parse_seq_hdr(void *sess,
1960 struct vidc_seq_hdr *seq_hdr)
1961{
1962 struct hfi_cmd_session_parse_sequence_header_packet *pkt;
1963 int rc = 0;
1964 u8 packet[VIDC_IFACEQ_VAR_SMALL_PKT_SIZE];
1965 struct hal_session *session;
1966
1967 if (!sess || !seq_hdr) {
Ashray Kulkarni000b3822012-10-11 18:20:58 -07001968 dprintk(VIDC_ERR, "Invalid Params");
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08001969 return -EINVAL;
1970 } else {
1971 session = sess;
1972 }
1973
1974 pkt = (struct hfi_cmd_session_parse_sequence_header_packet *) packet;
1975 pkt->size = sizeof(struct hfi_cmd_session_parse_sequence_header_packet);
1976 pkt->packet_type = HFI_CMD_SESSION_PARSE_SEQUENCE_HEADER;
1977 pkt->session_id = (u32) session;
1978 pkt->header_len = seq_hdr->seq_hdr_len;
1979 pkt->packet_buffer = seq_hdr->seq_hdr;
1980
1981 if (vidc_hal_iface_cmdq_write(session->device, pkt))
1982 rc = -ENOTEMPTY;
1983 return rc;
1984}
1985
1986int vidc_hal_session_get_seq_hdr(void *sess,
1987 struct vidc_seq_hdr *seq_hdr)
1988{
1989 struct hfi_cmd_session_get_sequence_header_packet *pkt;
1990 int rc = 0;
1991 u8 packet[VIDC_IFACEQ_VAR_SMALL_PKT_SIZE];
1992 struct hal_session *session;
1993
1994 if (!sess || !seq_hdr) {
Ashray Kulkarni000b3822012-10-11 18:20:58 -07001995 dprintk(VIDC_ERR, "Invalid Params");
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08001996 return -EINVAL;
1997 } else {
1998 session = sess;
1999 }
2000
2001 pkt = (struct hfi_cmd_session_get_sequence_header_packet *) packet;
2002 pkt->size = sizeof(struct hfi_cmd_session_get_sequence_header_packet);
2003 pkt->packet_type = HFI_CMD_SESSION_GET_SEQUENCE_HEADER;
2004 pkt->session_id = (u32) session;
2005 pkt->buffer_len = seq_hdr->seq_hdr_len;
2006 pkt->packet_buffer = seq_hdr->seq_hdr;
2007
2008 if (vidc_hal_iface_cmdq_write(session->device, pkt))
2009 rc = -ENOTEMPTY;
2010 return rc;
2011}
2012
2013int vidc_hal_session_get_buf_req(void *sess)
2014{
2015 struct hfi_cmd_session_get_property_packet pkt;
2016 int rc = 0;
2017 struct hal_session *session;
2018
2019 if (sess) {
2020 session = sess;
2021 } else {
Ashray Kulkarni000b3822012-10-11 18:20:58 -07002022 dprintk(VIDC_ERR, "invalid session");
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08002023 return -ENODEV;
2024 }
2025
2026 pkt.size = sizeof(struct hfi_cmd_session_get_property_packet);
2027 pkt.packet_type = HFI_CMD_SESSION_GET_PROPERTY;
2028 pkt.session_id = (u32) session;
2029 pkt.num_properties = 1;
2030 pkt.rg_property_data[0] = HFI_PROPERTY_CONFIG_BUFFER_REQUIREMENTS;
2031 if (vidc_hal_iface_cmdq_write(session->device, &pkt))
2032 rc = -ENOTEMPTY;
2033 return rc;
2034}
2035
2036int vidc_hal_session_flush(void *sess, enum hal_flush flush_mode)
2037{
2038 struct hfi_cmd_session_flush_packet pkt;
2039 int rc = 0;
2040 struct hal_session *session;
2041
2042 if (sess) {
2043 session = sess;
2044 } else {
Ashray Kulkarni000b3822012-10-11 18:20:58 -07002045 dprintk(VIDC_ERR, "invalid session");
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08002046 return -ENODEV;
2047 }
2048
2049 pkt.size = sizeof(struct hfi_cmd_session_flush_packet);
2050 pkt.packet_type = HFI_CMD_SESSION_FLUSH;
2051 pkt.session_id = (u32) session;
Ashray Kulkarnife72c452012-05-29 19:52:00 -07002052 switch (flush_mode) {
2053 case HAL_FLUSH_INPUT:
2054 pkt.flush_type = HFI_FLUSH_INPUT;
2055 break;
2056 case HAL_FLUSH_OUTPUT:
2057 pkt.flush_type = HFI_FLUSH_OUTPUT;
2058 break;
2059 case HAL_FLUSH_OUTPUT2:
2060 pkt.flush_type = HFI_FLUSH_OUTPUT2;
2061 break;
2062 case HAL_FLUSH_ALL:
2063 pkt.flush_type = HFI_FLUSH_ALL;
2064 break;
2065 default:
Blaine Dietrichf1a7cff2012-07-23 12:14:18 -07002066 dprintk(VIDC_ERR, "Invalid flush mode: 0x%x\n", flush_mode);
Ashray Kulkarnife72c452012-05-29 19:52:00 -07002067 break;
2068 }
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08002069 if (vidc_hal_iface_cmdq_write(session->device, &pkt))
2070 rc = -ENOTEMPTY;
2071 return rc;
2072}
2073
2074static int vidc_hal_check_core_registered(
2075 struct hal_device_data core, u32 fw_addr,
2076 u32 reg_addr, u32 reg_size, u32 irq)
2077{
2078 struct hal_device *device;
2079 struct list_head *curr, *next;
2080
2081 if (core.dev_count) {
2082 list_for_each_safe(curr, next, &core.dev_head) {
2083 device = list_entry(curr, struct hal_device, list);
2084 if (device && device->hal_data->irq == irq &&
Vinay Kalia68398a42012-06-22 18:36:12 -07002085 (CONTAINS(device->hal_data->
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08002086 device_base_addr,
2087 FIRMWARE_SIZE, fw_addr) ||
2088 CONTAINS(fw_addr, FIRMWARE_SIZE,
Vinay Kalia68398a42012-06-22 18:36:12 -07002089 device->hal_data->
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08002090 device_base_addr) ||
2091 CONTAINS((u32)device->hal_data->
2092 register_base_addr,
2093 reg_size, reg_addr) ||
2094 CONTAINS(reg_addr, reg_size,
2095 (u32)device->hal_data->
2096 register_base_addr) ||
2097 OVERLAPS((u32)device->hal_data->
2098 register_base_addr,
2099 reg_size, reg_addr, reg_size) ||
2100 OVERLAPS(reg_addr, reg_size,
2101 (u32)device->hal_data->
2102 register_base_addr, reg_size) ||
Vinay Kalia68398a42012-06-22 18:36:12 -07002103 OVERLAPS(device->hal_data->
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08002104 device_base_addr,
2105 FIRMWARE_SIZE, fw_addr,
2106 FIRMWARE_SIZE) ||
2107 OVERLAPS(fw_addr, FIRMWARE_SIZE,
Vinay Kalia68398a42012-06-22 18:36:12 -07002108 device->hal_data->
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08002109 device_base_addr,
2110 FIRMWARE_SIZE))) {
2111 return 0;
2112 } else {
Blaine Dietrichf1a7cff2012-07-23 12:14:18 -07002113 dprintk(VIDC_INFO, "Device not registered");
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08002114 return -EINVAL;
2115 }
2116 }
2117 } else {
Blaine Dietrichf1a7cff2012-07-23 12:14:18 -07002118 dprintk(VIDC_INFO, "no device Registered");
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08002119 }
2120 return -EINVAL;
2121}
2122
2123static void vidc_hal_core_work_handler(struct work_struct *work)
2124{
Deva Ramasubramanianc249b752012-05-18 17:31:03 -07002125 struct hal_device *device = list_first_entry(
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08002126 &hal_ctxt.dev_head, struct hal_device, list);
2127
Blaine Dietrichf1a7cff2012-07-23 12:14:18 -07002128 dprintk(VIDC_INFO, " GOT INTERRUPT () ");
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08002129 if (!device->callback) {
Blaine Dietrichf1a7cff2012-07-23 12:14:18 -07002130 dprintk(VIDC_ERR, "No callback function "
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08002131 "to process interrupt: %p\n", device);
2132 return;
2133 }
2134 vidc_hal_core_clear_interrupt(device);
2135 vidc_hal_response_handler(device);
2136 enable_irq(device->hal_data->irq);
2137}
2138static DECLARE_WORK(vidc_hal_work, vidc_hal_core_work_handler);
2139
2140static irqreturn_t vidc_hal_isr(int irq, void *dev)
2141{
2142 struct hal_device *device = dev;
Blaine Dietrichf1a7cff2012-07-23 12:14:18 -07002143 dprintk(VIDC_INFO, "vidc_hal_isr() %d ", irq);
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08002144 disable_irq_nosync(irq);
2145 queue_work(device->vidc_workq, &vidc_hal_work);
Blaine Dietrichf1a7cff2012-07-23 12:14:18 -07002146 dprintk(VIDC_INFO, "vidc_hal_isr() %d ", irq);
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08002147 return IRQ_HANDLED;
2148}
2149
2150void *vidc_hal_add_device(u32 device_id, u32 fw_base_addr, u32 reg_base,
2151 u32 reg_size, u32 irq,
2152 void (*callback) (enum command_response cmd, void *data))
2153{
2154 struct hal_device *hdevice = NULL;
2155 struct hal_data *hal = NULL;
2156 int rc = 0;
2157
Vinay Kalia68398a42012-06-22 18:36:12 -07002158 if (device_id || !reg_base || !reg_size ||
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08002159 !irq || !callback) {
Blaine Dietrichf1a7cff2012-07-23 12:14:18 -07002160 dprintk(VIDC_ERR, "Invalid Paramters");
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08002161 return NULL;
2162 } else {
Blaine Dietrichf1a7cff2012-07-23 12:14:18 -07002163 dprintk(VIDC_INFO, "entered , device_id: %d", device_id);
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08002164 }
2165
2166 if (vidc_hal_check_core_registered(hal_ctxt, fw_base_addr,
2167 reg_base, reg_size, irq)) {
Blaine Dietrichf1a7cff2012-07-23 12:14:18 -07002168 dprintk(VIDC_DBG, "HAL_DATA will be assigned now");
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08002169 hal = (struct hal_data *)
2170 kzalloc(sizeof(struct hal_data), GFP_KERNEL);
2171 if (!hal) {
Blaine Dietrichf1a7cff2012-07-23 12:14:18 -07002172 dprintk(VIDC_ERR, "Failed to alloc");
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08002173 return NULL;
2174 }
2175 hal->irq = irq;
Vinay Kalia68398a42012-06-22 18:36:12 -07002176 hal->device_base_addr = fw_base_addr;
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08002177 hal->register_base_addr =
2178 ioremap_nocache(reg_base, reg_size);
2179 if (!hal->register_base_addr) {
Blaine Dietrichf1a7cff2012-07-23 12:14:18 -07002180 dprintk(VIDC_ERR,
2181 "could not map reg addr %d of size %d",
2182 reg_base, reg_size);
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08002183 goto err_map;
2184 }
2185 INIT_LIST_HEAD(&hal_ctxt.dev_head);
2186 } else {
Blaine Dietrichf1a7cff2012-07-23 12:14:18 -07002187 dprintk(VIDC_ERR, "Core present/Already added");
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08002188 return NULL;
2189 }
2190
2191 hdevice = (struct hal_device *)
2192 kzalloc(sizeof(struct hal_device), GFP_KERNEL);
2193 if (!hdevice) {
Blaine Dietrichf1a7cff2012-07-23 12:14:18 -07002194 dprintk(VIDC_ERR, "failed to allocate new device");
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08002195 goto err_map;
2196 }
2197
2198 INIT_LIST_HEAD(&hdevice->list);
2199 list_add_tail(&hdevice->list, &hal_ctxt.dev_head);
2200 hal_ctxt.dev_count++;
2201 hdevice->device_id = device_id;
2202 hdevice->hal_data = hal;
2203 hdevice->callback = callback;
2204
2205 hdevice->vidc_workq = create_singlethread_workqueue(
2206 "msm_vidc_workerq");
2207 if (!hdevice->vidc_workq) {
Blaine Dietrichf1a7cff2012-07-23 12:14:18 -07002208 dprintk(VIDC_ERR, ": create workq failed\n");
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08002209 goto error_createq;
2210 }
2211
2212 rc = request_irq(irq, vidc_hal_isr, IRQF_TRIGGER_HIGH,
2213 "msm_vidc", hdevice);
2214 if (unlikely(rc)) {
Blaine Dietrichf1a7cff2012-07-23 12:14:18 -07002215 dprintk(VIDC_ERR, "() :request_irq failed\n");
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08002216 goto error_irq_fail;
2217 }
2218 disable_irq_nosync(irq);
2219 return (void *) hdevice;
2220error_irq_fail:
2221 destroy_workqueue(hdevice->vidc_workq);
2222error_createq:
2223 hal_ctxt.dev_count--;
2224 list_del(&hal_ctxt.dev_head);
2225err_map:
2226 kfree(hal);
2227 return NULL;
2228}
2229
2230void vidc_hal_delete_device(void *device)
2231{
2232 struct hal_device *close, *dev;
2233
2234 if (device) {
2235 dev = (struct hal_device *) device;
2236 list_for_each_entry(close, &hal_ctxt.dev_head, list) {
2237 if (close->hal_data->irq == dev->hal_data->irq) {
2238 hal_ctxt.dev_count--;
2239 free_irq(dev->hal_data->irq, NULL);
2240 list_del(&close->list);
2241 destroy_workqueue(close->vidc_workq);
2242 kfree(close->hal_data);
2243 kfree(close);
2244 break;
2245 }
2246 }
2247
2248 }
2249}