blob: aa3064469265429ba33e481dd7fdc2c21afc408e [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,
595 VIDC_WRAPPER_INTR_MASK, 0, 0);
596 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,
Vinay Kalia15e870b2012-09-10 15:30:23 -0700616 VIDC_VBIF_OUT_AXI_AOOO_EN, 0x00000FFF, 0);
Vinay Kaliacdf8d0c2012-08-28 12:07:36 -0700617 write_register(device->hal_data->register_base_addr,
Vinay Kalia15e870b2012-09-10 15:30:23 -0700618 VIDC_VBIF_OUT_AXI_AOOO, 0x0FFF0FFF, 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_VENUS_VBIF_CLK_ON, 1, 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_CONF0, 0x10101001, 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_CONF1, 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_CONF2, 0x10101010, 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_RD_LIM_CONF3, 0x00000010, 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_CONF0, 0x1010100f, 0);
Vinay Kaliacdf8d0c2012-08-28 12:07:36 -0700631 write_register(device->hal_data->register_base_addr,
Vinay Kalia15e870b2012-09-10 15:30:23 -0700632 VIDC_VBIF_IN_WR_LIM_CONF1, 0x10101010, 0);
633 write_register(device->hal_data->register_base_addr,
634 VIDC_VBIF_IN_WR_LIM_CONF2, 0x10101010, 0);
635 write_register(device->hal_data->register_base_addr,
636 VIDC_VBIF_IN_WR_LIM_CONF3, 0x00000010, 0);
637 write_register(device->hal_data->register_base_addr,
638 VIDC_VBIF_OUT_RD_LIM_CONF0, 0x00001010, 0);
639 write_register(device->hal_data->register_base_addr,
640 VIDC_VBIF_OUT_WR_LIM_CONF0, 0x00001010, 0);
641 write_register(device->hal_data->register_base_addr,
642 VIDC_VBIF_ARB_CTL, 0x00000030, 0);
Vinay Kaliab717b9d2012-09-14 12:00:45 -0700643 write_register(device->hal_data->register_base_addr,
644 VIDC_VENUS0_WRAPPER_VBIF_REQ_PRIORITY, 0x5555556, 0);
Vinay Kaliacdf8d0c2012-08-28 12:07:36 -0700645}
646
Vinay Kalia68398a42012-06-22 18:36:12 -0700647int vidc_hal_core_init(void *device, int domain)
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -0800648{
649 struct hfi_cmd_sys_init_packet pkt;
650 int rc = 0;
651 struct hal_device *dev;
652
653 if (device) {
654 dev = device;
655 } else {
Ashray Kulkarnib6734502012-08-24 13:00:22 -0700656 dprintk(VIDC_ERR, "Invalid device");
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -0800657 return -ENODEV;
658 }
659 enable_irq(dev->hal_data->irq);
660 INIT_LIST_HEAD(&dev->sess_head);
661 spin_lock_init(&dev->read_lock);
662 spin_lock_init(&dev->write_lock);
Vinay Kaliacdf8d0c2012-08-28 12:07:36 -0700663 set_vbif_registers(dev);
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -0800664 if (!dev->hal_client) {
665 dev->hal_client = msm_smem_new_client(SMEM_ION);
666 if (dev->hal_client == NULL) {
Blaine Dietrichf1a7cff2012-07-23 12:14:18 -0700667 dprintk(VIDC_ERR, "Failed to alloc ION_Client");
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -0800668 rc = -ENODEV;
669 goto err_no_mem;
670 }
671
Blaine Dietrichf1a7cff2012-07-23 12:14:18 -0700672 dprintk(VIDC_DBG, "Device_Virt_Address : 0x%x,"
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -0800673 "Register_Virt_Addr: 0x%x",
Vinay Kalia68398a42012-06-22 18:36:12 -0700674 dev->hal_data->device_base_addr,
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -0800675 (u32) dev->hal_data->register_base_addr);
676
Vinay Kalia68398a42012-06-22 18:36:12 -0700677 rc = vidc_hal_interface_queues_init(dev, domain);
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -0800678 if (rc) {
Blaine Dietrichf1a7cff2012-07-23 12:14:18 -0700679 dprintk(VIDC_ERR, "failed to init queues");
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -0800680 rc = -ENOMEM;
681 goto err_no_mem;
682 }
683 } else {
Blaine Dietrichf1a7cff2012-07-23 12:14:18 -0700684 dprintk(VIDC_ERR, "hal_client exists");
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -0800685 rc = -EEXIST;
686 goto err_no_mem;
687 }
688 rc = vidc_hal_core_start_cpu(dev);
689 if (rc) {
Blaine Dietrichf1a7cff2012-07-23 12:14:18 -0700690 dprintk(VIDC_ERR, "Failed to start core");
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -0800691 rc = -ENODEV;
692 goto err_no_dev;
693 }
694 pkt.size = sizeof(struct hfi_cmd_sys_init_packet);
Ashray Kulkarnife72c452012-05-29 19:52:00 -0700695 pkt.packet_type = HFI_CMD_SYS_INIT;
696 pkt.arch_type = HFI_ARCH_OX_OFFSET;
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -0800697 if (vidc_hal_iface_cmdq_write(dev, &pkt)) {
698 rc = -ENOTEMPTY;
699 goto err_write_fail;
700 }
701 return rc;
702err_no_dev:
703err_write_fail:
704err_no_mem:
705 disable_irq_nosync(dev->hal_data->irq);
706 return rc;
707}
708
709int vidc_hal_core_release(void *device)
710{
711 struct hal_device *dev;
712 if (device) {
713 dev = device;
714 } else {
Ashray Kulkarnib6734502012-08-24 13:00:22 -0700715 dprintk(VIDC_ERR, "invalid device");
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -0800716 return -ENODEV;
717 }
718 write_register(dev->hal_data->register_base_addr,
719 VIDC_CPU_CS_SCIACMDARG3, 0, 0);
Vinay Kalia40c3ae82012-07-09 15:23:02 -0700720 disable_irq_nosync(dev->hal_data->irq);
721 vidc_hal_interface_queues_release(dev);
Blaine Dietrichf1a7cff2012-07-23 12:14:18 -0700722 dprintk(VIDC_INFO, "HAL exited\n");
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -0800723 return 0;
724}
725
726int vidc_hal_core_pc_prep(void *device)
727{
728 struct hfi_cmd_sys_pc_prep_packet pkt;
729 int rc = 0;
730 struct hal_device *dev;
731
732 if (device) {
733 dev = device;
734 } else {
Ashray Kulkarnib6734502012-08-24 13:00:22 -0700735 dprintk(VIDC_ERR, "invalid device");
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -0800736 return -ENODEV;
737 }
738 pkt.size = sizeof(struct hfi_cmd_sys_pc_prep_packet);
739 pkt.packet_type = HFI_CMD_SYS_PC_PREP;
740 if (vidc_hal_iface_cmdq_write(dev, &pkt))
741 rc = -ENOTEMPTY;
742 return rc;
743}
744
745static void vidc_hal_core_clear_interrupt(struct hal_device *device)
746{
747 u32 intr_status = 0;
748
749 if (!device->callback)
750 return;
751
752 intr_status = read_register(
753 device->hal_data->register_base_addr,
754 VIDC_WRAPPER_INTR_STATUS);
755
756 if ((intr_status & VIDC_WRAPPER_INTR_STATUS_A2H_BMSK) ||
757 (intr_status & VIDC_WRAPPER_INTR_STATUS_A2HWD_BMSK)) {
758 device->intr_status |= intr_status;
Blaine Dietrichf1a7cff2012-07-23 12:14:18 -0700759 dprintk(VIDC_DBG, "INTERRUPT for device: 0x%x: "
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -0800760 "times: %d interrupt_status: %d",
761 (u32) device, ++device->reg_count, intr_status);
762 } else {
Ashray Kulkarni000b3822012-10-11 18:20:58 -0700763 dprintk(VIDC_INFO, "SPURIOUS_INTR for device: 0x%x: "
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -0800764 "times: %d interrupt_status: %d",
765 (u32) device, ++device->spur_count, intr_status);
766 }
767 write_register(device->hal_data->register_base_addr,
768 VIDC_CPU_CS_A2HSOFTINTCLR, 1, 0);
769 write_register(device->hal_data->register_base_addr,
770 VIDC_WRAPPER_INTR_CLEAR, intr_status, 0);
Blaine Dietrichf1a7cff2012-07-23 12:14:18 -0700771 dprintk(VIDC_DBG, "Cleared WRAPPER/A2H interrupt");
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -0800772}
773
774int vidc_hal_core_set_resource(void *device,
775 struct vidc_resource_hdr *resource_hdr, void *resource_value)
776{
777 struct hfi_cmd_sys_set_resource_packet *pkt;
778 u8 packet[VIDC_IFACEQ_VAR_SMALL_PKT_SIZE];
779 int rc = 0;
780 struct hal_device *dev;
781
782 if (!device || !resource_hdr || !resource_value) {
Ashray Kulkarnib6734502012-08-24 13:00:22 -0700783 dprintk(VIDC_ERR, "set_res: Invalid Params");
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -0800784 return -EINVAL;
785 } else {
786 dev = device;
787 }
788
789 pkt = (struct hfi_cmd_sys_set_resource_packet *) packet;
790
791 pkt->size = sizeof(struct hfi_cmd_sys_set_resource_packet);
792 pkt->packet_type = HFI_CMD_SYS_SET_RESOURCE;
793 pkt->resource_handle = resource_hdr->resource_handle;
794
795 switch (resource_hdr->resource_id) {
796 case VIDC_RESOURCE_OCMEM:
797 {
Ashray Kulkarnife72c452012-05-29 19:52:00 -0700798 struct hfi_resource_ocmem *hfioc_mem =
799 (struct hfi_resource_ocmem *)
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -0800800 &pkt->rg_resource_data[0];
Vinay Kaliabc9f60a2012-07-17 01:23:42 -0700801 struct ocmem_buf *ocmem =
802 (struct ocmem_buf *) resource_value;
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -0800803
804 pkt->resource_type = HFI_RESOURCE_OCMEM;
Vinay Kaliabc9f60a2012-07-17 01:23:42 -0700805 hfioc_mem->size = (u32) ocmem->len;
806 hfioc_mem->mem = (u8 *) ocmem->addr;
Ashray Kulkarnife72c452012-05-29 19:52:00 -0700807 pkt->size += sizeof(struct hfi_resource_ocmem);
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -0800808 if (vidc_hal_iface_cmdq_write(dev, pkt))
809 rc = -ENOTEMPTY;
810 break;
811 }
812 default:
Ashray Kulkarnib6734502012-08-24 13:00:22 -0700813 dprintk(VIDC_INFO, "Invalid res_id in set_res %d",
Blaine Dietrichf1a7cff2012-07-23 12:14:18 -0700814 resource_hdr->resource_id);
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -0800815 break;
816 }
817 return rc;
818}
819
820int vidc_hal_core_release_resource(void *device,
821 struct vidc_resource_hdr *resource_hdr)
822{
823 struct hfi_cmd_sys_release_resource_packet pkt;
824 int rc = 0;
825 struct hal_device *dev;
826
827 if (!device || !resource_hdr) {
Ashray Kulkarnib6734502012-08-24 13:00:22 -0700828 dprintk(VIDC_ERR, "Inv-Params in rel_res");
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -0800829 return -EINVAL;
830 } else {
831 dev = device;
832 }
833
834 pkt.size = sizeof(struct hfi_cmd_sys_release_resource_packet);
835 pkt.packet_type = HFI_CMD_SYS_RELEASE_RESOURCE;
836 pkt.resource_type = resource_hdr->resource_id;
837 pkt.resource_handle = resource_hdr->resource_handle;
838
839 if (vidc_hal_iface_cmdq_write(dev, &pkt))
840 rc = -ENOTEMPTY;
841 return rc;
842}
843
844int vidc_hal_core_ping(void *device)
845{
846 struct hfi_cmd_sys_ping_packet pkt;
847 int rc = 0;
848 struct hal_device *dev;
849
850 if (device) {
851 dev = device;
852 } else {
Ashray Kulkarnib6734502012-08-24 13:00:22 -0700853 dprintk(VIDC_ERR, "invalid device");
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -0800854 return -ENODEV;
855 }
856 pkt.size = sizeof(struct hfi_cmd_sys_ping_packet);
857 pkt.packet_type = HFI_CMD_SYS_PING;
858
859 if (vidc_hal_iface_cmdq_write(dev, &pkt))
860 rc = -ENOTEMPTY;
861 return rc;
862}
Ashray Kulkarnife72c452012-05-29 19:52:00 -0700863static u32 get_hfi_buffer(int hal_buffer)
864{
865 u32 buffer;
866 switch (hal_buffer) {
867 case HAL_BUFFER_INPUT:
868 buffer = HFI_BUFFER_INPUT;
869 break;
870 case HAL_BUFFER_OUTPUT:
871 buffer = HFI_BUFFER_OUTPUT;
872 break;
873 case HAL_BUFFER_OUTPUT2:
874 buffer = HFI_BUFFER_OUTPUT;
875 break;
876 case HAL_BUFFER_EXTRADATA_INPUT:
877 buffer = HFI_BUFFER_EXTRADATA_INPUT;
878 break;
879 case HAL_BUFFER_EXTRADATA_OUTPUT:
880 buffer = HFI_BUFFER_EXTRADATA_OUTPUT;
881 break;
882 case HAL_BUFFER_EXTRADATA_OUTPUT2:
883 buffer = HFI_BUFFER_EXTRADATA_OUTPUT2;
884 break;
885 case HAL_BUFFER_INTERNAL_SCRATCH:
886 buffer = HFI_BUFFER_INTERNAL_SCRATCH;
887 break;
888 case HAL_BUFFER_INTERNAL_PERSIST:
889 buffer = HFI_BUFFER_INTERNAL_PERSIST;
890 break;
891 default:
Ashray Kulkarnib6734502012-08-24 13:00:22 -0700892 dprintk(VIDC_ERR, "Invalid buffer :0x%x\n",
893 hal_buffer);
Ashray Kulkarnife72c452012-05-29 19:52:00 -0700894 buffer = 0;
895 break;
896 }
897 return buffer;
898}
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -0800899int vidc_hal_session_set_property(void *sess,
900 enum hal_property ptype, void *pdata)
901{
902 u8 packet[VIDC_IFACEQ_VAR_LARGE_PKT_SIZE];
903 struct hfi_cmd_session_set_property_packet *pkt =
904 (struct hfi_cmd_session_set_property_packet *) &packet;
905 struct hal_session *session;
906
907 if (!sess || !pdata) {
Ashray Kulkarnib6734502012-08-24 13:00:22 -0700908 dprintk(VIDC_ERR, "Invalid Params");
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -0800909 return -EINVAL;
910 } else {
911 session = sess;
912 }
913
Ashray Kulkarnib6734502012-08-24 13:00:22 -0700914 dprintk(VIDC_INFO, "in set_prop,with prop id: 0x%x", ptype);
Ashray Kulkarni1c72b392012-06-20 10:50:00 -0700915 pkt->size = sizeof(struct hfi_cmd_session_set_property_packet);
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -0800916 pkt->packet_type = HFI_CMD_SESSION_SET_PROPERTY;
917 pkt->session_id = (u32) session;
918 pkt->num_properties = 1;
919
920 switch (ptype) {
921 case HAL_CONFIG_FRAME_RATE:
Ashray Kulkarni1ccbc912012-03-23 16:26:52 -0700922 {
Ashray Kulkarnife72c452012-05-29 19:52:00 -0700923 struct hfi_frame_rate *hfi;
924 u32 buffer;
925 struct hal_frame_rate *prop =
926 (struct hal_frame_rate *) pdata;
Ashray Kulkarni1ccbc912012-03-23 16:26:52 -0700927 pkt->rg_property_data[0] = HFI_PROPERTY_CONFIG_FRAME_RATE;
Ashray Kulkarnife72c452012-05-29 19:52:00 -0700928 hfi = (struct hfi_frame_rate *) &pkt->rg_property_data[1];
929 buffer = get_hfi_buffer(prop->buffer_type);
930 if (buffer)
931 hfi->buffer_type = buffer;
932 else
933 return -EINVAL;
934 hfi->frame_rate = prop->frame_rate;
Ashray Kulkarni1ccbc912012-03-23 16:26:52 -0700935 pkt->size += sizeof(u32) + sizeof(struct hfi_frame_rate);
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -0800936 break;
Ashray Kulkarni1ccbc912012-03-23 16:26:52 -0700937 }
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -0800938 case HAL_PARAM_UNCOMPRESSED_FORMAT_SELECT:
939 {
Ashray Kulkarnife72c452012-05-29 19:52:00 -0700940 u32 buffer;
941 struct hfi_uncompressed_format_select *hfi;
942 struct hal_uncompressed_format_select *prop =
943 (struct hal_uncompressed_format_select *) pdata;
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -0800944 pkt->rg_property_data[0] =
945 HFI_PROPERTY_PARAM_UNCOMPRESSED_FORMAT_SELECT;
Ashray Kulkarnife72c452012-05-29 19:52:00 -0700946 hfi = (struct hfi_uncompressed_format_select *)
947 &pkt->rg_property_data[1];
948 buffer = get_hfi_buffer(prop->buffer_type);
949 if (buffer)
950 hfi->buffer_type = buffer;
951 else
952 return -EINVAL;
953 hfi->format = prop->format;
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -0800954 pkt->size += sizeof(u32) + sizeof(struct
955 hfi_uncompressed_format_select);
956 break;
957 }
958 case HAL_PARAM_UNCOMPRESSED_PLANE_ACTUAL_CONSTRAINTS_INFO:
959 break;
960 case HAL_PARAM_UNCOMPRESSED_PLANE_ACTUAL_INFO:
961 break;
962 case HAL_PARAM_EXTRA_DATA_HEADER_CONFIG:
963 break;
964 case HAL_PARAM_FRAME_SIZE:
965 {
Ashray Kulkarnife72c452012-05-29 19:52:00 -0700966 u32 buffer;
967 struct hfi_frame_size *hfi;
968 struct hal_frame_size *prop = (struct hal_frame_size *) pdata;
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -0800969 pkt->rg_property_data[0] = HFI_PROPERTY_PARAM_FRAME_SIZE;
Ashray Kulkarnife72c452012-05-29 19:52:00 -0700970 hfi = (struct hfi_frame_size *) &pkt->rg_property_data[1];
971 buffer = get_hfi_buffer(prop->buffer_type);
972 if (buffer)
973 hfi->buffer_type = buffer;
974 else
975 return -EINVAL;
976 hfi->height = prop->height;
977 hfi->width = prop->width;
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -0800978 pkt->size += sizeof(u32) + sizeof(struct hfi_frame_size);
979 break;
980 }
981 case HAL_CONFIG_REALTIME:
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -0800982 {
Ashray Kulkarni1ccbc912012-03-23 16:26:52 -0700983 struct hfi_enable *hfi;
984 pkt->rg_property_data[0] = HFI_PROPERTY_CONFIG_REALTIME;
985 hfi = (struct hfi_enable *) &pkt->rg_property_data[1];
Ashray Kulkarnife72c452012-05-29 19:52:00 -0700986 hfi->enable = ((struct hfi_enable *) pdata)->enable;
987 pkt->size += sizeof(u32) * 2;
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -0800988 break;
989 }
Ashray Kulkarni1ccbc912012-03-23 16:26:52 -0700990 case HAL_PARAM_BUFFER_COUNT_ACTUAL:
991 {
Ashray Kulkarnife72c452012-05-29 19:52:00 -0700992 u32 buffer;
Ashray Kulkarni1ccbc912012-03-23 16:26:52 -0700993 struct hfi_buffer_count_actual *hfi;
Ashray Kulkarnife72c452012-05-29 19:52:00 -0700994 struct hal_buffer_count_actual *prop =
995 (struct hal_buffer_count_actual *) pdata;
Ashray Kulkarni1ccbc912012-03-23 16:26:52 -0700996 pkt->rg_property_data[0] =
997 HFI_PROPERTY_PARAM_BUFFER_COUNT_ACTUAL;
998 hfi = (struct hfi_buffer_count_actual *)
999 &pkt->rg_property_data[1];
Ashray Kulkarnife72c452012-05-29 19:52:00 -07001000 hfi->buffer_count_actual = prop->buffer_count_actual;
1001 buffer = get_hfi_buffer(prop->buffer_type);
1002 if (buffer)
1003 hfi->buffer_type = buffer;
1004 else
1005 return -EINVAL;
Ashray Kulkarni1ccbc912012-03-23 16:26:52 -07001006 pkt->size += sizeof(u32) + sizeof(struct
1007 hfi_buffer_count_actual);
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08001008 break;
Ashray Kulkarni1ccbc912012-03-23 16:26:52 -07001009 }
1010 case HAL_PARAM_NAL_STREAM_FORMAT_SELECT:
1011 {
Ashray Kulkarnife72c452012-05-29 19:52:00 -07001012 struct hal_nal_stream_format_supported *prop =
1013 (struct hal_nal_stream_format_supported *)pdata;
Ashray Kulkarni1ccbc912012-03-23 16:26:52 -07001014 pkt->rg_property_data[0] =
1015 HFI_PROPERTY_PARAM_NAL_STREAM_FORMAT_SELECT;
Blaine Dietrichf1a7cff2012-07-23 12:14:18 -07001016 dprintk(VIDC_DBG, "data is :%d",
Ashray Kulkarnife72c452012-05-29 19:52:00 -07001017 prop->nal_stream_format_supported);
1018 switch (prop->nal_stream_format_supported) {
1019 case HAL_NAL_FORMAT_STARTCODES:
1020 pkt->rg_property_data[1] =
1021 HFI_NAL_FORMAT_STARTCODES;
1022 break;
1023 case HAL_NAL_FORMAT_ONE_NAL_PER_BUFFER:
1024 pkt->rg_property_data[1] =
1025 HFI_NAL_FORMAT_ONE_NAL_PER_BUFFER;
1026 break;
1027 case HAL_NAL_FORMAT_ONE_BYTE_LENGTH:
1028 pkt->rg_property_data[1] =
1029 HFI_NAL_FORMAT_ONE_BYTE_LENGTH;
1030 break;
1031 case HAL_NAL_FORMAT_TWO_BYTE_LENGTH:
1032 pkt->rg_property_data[1] =
1033 HFI_NAL_FORMAT_TWO_BYTE_LENGTH;
1034 break;
1035 case HAL_NAL_FORMAT_FOUR_BYTE_LENGTH:
1036 pkt->rg_property_data[1] =
1037 HFI_NAL_FORMAT_FOUR_BYTE_LENGTH;
1038 break;
1039 default:
Blaine Dietrichf1a7cff2012-07-23 12:14:18 -07001040 dprintk(VIDC_ERR, "Invalid nal format: 0x%x",
Ashray Kulkarnife72c452012-05-29 19:52:00 -07001041 prop->nal_stream_format_supported);
1042 break;
1043 }
1044 pkt->size += sizeof(u32) * 2;
Ashray Kulkarni1ccbc912012-03-23 16:26:52 -07001045 break;
1046 }
1047 case HAL_PARAM_VDEC_OUTPUT_ORDER:
1048 {
Ashray Kulkarnife72c452012-05-29 19:52:00 -07001049 int *data = (int *) pdata;
Ashray Kulkarni1ccbc912012-03-23 16:26:52 -07001050 pkt->rg_property_data[0] =
1051 HFI_PROPERTY_PARAM_VDEC_OUTPUT_ORDER;
Ashray Kulkarnife72c452012-05-29 19:52:00 -07001052 switch (*data) {
1053 case HAL_OUTPUT_ORDER_DECODE:
Ashray Kulkarni995fd272012-07-02 12:57:55 -07001054 pkt->rg_property_data[1] = HFI_OUTPUT_ORDER_DECODE;
Ashray Kulkarnife72c452012-05-29 19:52:00 -07001055 break;
1056 case HAL_OUTPUT_ORDER_DISPLAY:
Ashray Kulkarni995fd272012-07-02 12:57:55 -07001057 pkt->rg_property_data[1] = HFI_OUTPUT_ORDER_DISPLAY;
Ashray Kulkarnife72c452012-05-29 19:52:00 -07001058 break;
1059 default:
Blaine Dietrichf1a7cff2012-07-23 12:14:18 -07001060 dprintk(VIDC_ERR, "invalid output order: 0x%x",
Ashray Kulkarnife72c452012-05-29 19:52:00 -07001061 *data);
1062 break;
1063 }
1064 pkt->size += sizeof(u32) * 2;
Ashray Kulkarni1ccbc912012-03-23 16:26:52 -07001065 break;
1066 }
1067 case HAL_PARAM_VDEC_PICTURE_TYPE_DECODE:
1068 {
1069 struct hfi_enable_picture *hfi;
1070 pkt->rg_property_data[0] =
1071 HFI_PROPERTY_PARAM_VDEC_PICTURE_TYPE_DECODE;
1072 hfi = (struct hfi_enable_picture *) &pkt->rg_property_data[1];
1073 hfi->picture_type = (u32) pdata;
Ashray Kulkarnife72c452012-05-29 19:52:00 -07001074 pkt->size += sizeof(u32) * 2;
Ashray Kulkarni1ccbc912012-03-23 16:26:52 -07001075 break;
1076 }
1077 case HAL_PARAM_VDEC_OUTPUT2_KEEP_ASPECT_RATIO:
1078 {
1079 struct hfi_enable *hfi;
1080 pkt->rg_property_data[0] =
1081 HFI_PROPERTY_PARAM_VDEC_OUTPUT2_KEEP_ASPECT_RATIO;
1082 hfi = (struct hfi_enable *) &pkt->rg_property_data[1];
Ashray Kulkarnife72c452012-05-29 19:52:00 -07001083 hfi->enable = ((struct hfi_enable *) pdata)->enable;
1084 pkt->size += sizeof(u32) * 2;
Ashray Kulkarni1ccbc912012-03-23 16:26:52 -07001085 break;
1086 }
1087 case HAL_CONFIG_VDEC_POST_LOOP_DEBLOCKER:
1088 {
1089 struct hfi_enable *hfi;
1090 pkt->rg_property_data[0] =
1091 HFI_PROPERTY_CONFIG_VDEC_POST_LOOP_DEBLOCKER;
1092 hfi = (struct hfi_enable *) &pkt->rg_property_data[1];
Ashray Kulkarnife72c452012-05-29 19:52:00 -07001093 hfi->enable = ((struct hfi_enable *) pdata)->enable;
1094 pkt->size += sizeof(u32) * 2;
Ashray Kulkarni1ccbc912012-03-23 16:26:52 -07001095 break;
1096 }
1097 case HAL_PARAM_VDEC_MULTI_STREAM:
1098 {
Ashray Kulkarnife72c452012-05-29 19:52:00 -07001099 u32 buffer;
Ashray Kulkarni1ccbc912012-03-23 16:26:52 -07001100 struct hfi_multi_stream *hfi;
Ashray Kulkarnife72c452012-05-29 19:52:00 -07001101 struct hal_multi_stream *prop =
1102 (struct hal_multi_stream *) pdata;
Ashray Kulkarni1ccbc912012-03-23 16:26:52 -07001103 pkt->rg_property_data[0] =
1104 HFI_PROPERTY_PARAM_VDEC_MULTI_STREAM;
1105 hfi = (struct hfi_multi_stream *) &pkt->rg_property_data[1];
Ashray Kulkarnife72c452012-05-29 19:52:00 -07001106 buffer = get_hfi_buffer(prop->buffer_type);
1107 if (buffer)
1108 hfi->buffer_type = buffer;
1109 else
1110 return -EINVAL;
1111 hfi->enable = prop->enable;
1112 hfi->width = prop->width;
1113 hfi->height = prop->height;
Ashray Kulkarni1ccbc912012-03-23 16:26:52 -07001114 pkt->size += sizeof(u32) + sizeof(struct hfi_multi_stream);
1115 break;
1116 }
1117 case HAL_PARAM_VDEC_DISPLAY_PICTURE_BUFFER_COUNT:
1118 {
Ashray Kulkarnife72c452012-05-29 19:52:00 -07001119 struct hfi_display_picture_buffer_count *hfi;
1120 struct hal_display_picture_buffer_count *prop =
1121 (struct hal_display_picture_buffer_count *) pdata;
Ashray Kulkarni1ccbc912012-03-23 16:26:52 -07001122 pkt->rg_property_data[0] =
1123 HFI_PROPERTY_PARAM_VDEC_DISPLAY_PICTURE_BUFFER_COUNT;
Ashray Kulkarnife72c452012-05-29 19:52:00 -07001124 hfi = (struct hfi_display_picture_buffer_count *)
Ashray Kulkarni1ccbc912012-03-23 16:26:52 -07001125 &pkt->rg_property_data[1];
Ashray Kulkarnife72c452012-05-29 19:52:00 -07001126 hfi->count = prop->count;
1127 hfi->enable = prop->enable;
Ashray Kulkarni1ccbc912012-03-23 16:26:52 -07001128 pkt->size += sizeof(u32) +
1129 sizeof(struct hfi_display_picture_buffer_count);
1130 break;
1131 }
1132 case HAL_PARAM_DIVX_FORMAT:
1133 {
Ashray Kulkarnife72c452012-05-29 19:52:00 -07001134 int *data = pdata;
Ashray Kulkarni1ccbc912012-03-23 16:26:52 -07001135 pkt->rg_property_data[0] = HFI_PROPERTY_PARAM_DIVX_FORMAT;
Ashray Kulkarnife72c452012-05-29 19:52:00 -07001136 switch (*data) {
1137 case HAL_DIVX_FORMAT_4:
1138 pkt->rg_property_data[1] = HFI_DIVX_FORMAT_4;
1139 break;
1140 case HAL_DIVX_FORMAT_5:
1141 pkt->rg_property_data[1] = HFI_DIVX_FORMAT_5;
1142 break;
1143 case HAL_DIVX_FORMAT_6:
1144 pkt->rg_property_data[1] = HFI_DIVX_FORMAT_6;
1145 break;
1146 default:
Blaine Dietrichf1a7cff2012-07-23 12:14:18 -07001147 dprintk(VIDC_ERR, "Invalid divx format: 0x%x", *data);
Ashray Kulkarnife72c452012-05-29 19:52:00 -07001148 break;
1149 }
1150 pkt->size += sizeof(u32) * 2;
Ashray Kulkarni1ccbc912012-03-23 16:26:52 -07001151 break;
1152 }
1153 case HAL_CONFIG_VDEC_MB_ERROR_MAP_REPORTING:
1154 {
1155 struct hfi_enable *hfi;
1156 pkt->rg_property_data[0] =
1157 HFI_PROPERTY_CONFIG_VDEC_MB_ERROR_MAP_REPORTING;
1158 hfi = (struct hfi_enable *) &pkt->rg_property_data[1];
Ashray Kulkarnife72c452012-05-29 19:52:00 -07001159 hfi->enable = ((struct hfi_enable *) pdata)->enable;
1160 pkt->size += sizeof(u32) * 2;
Ashray Kulkarni1ccbc912012-03-23 16:26:52 -07001161 break;
1162 }
1163 case HAL_PARAM_VDEC_CONTINUE_DATA_TRANSFER:
1164 {
Ashray Kulkarnife72c452012-05-29 19:52:00 -07001165 struct hfi_enable *hfi;
Ashray Kulkarni1ccbc912012-03-23 16:26:52 -07001166 pkt->rg_property_data[0] =
1167 HFI_PROPERTY_PARAM_VDEC_CONTINUE_DATA_TRANSFER;
Ashray Kulkarnife72c452012-05-29 19:52:00 -07001168 hfi = (struct hfi_enable *) &pkt->rg_property_data[1];
1169 hfi->enable = ((struct hfi_enable *) pdata)->enable;
1170 pkt->size += sizeof(u32) * 2;
Ashray Kulkarni1ccbc912012-03-23 16:26:52 -07001171 break;
1172 }
Ashray Kulkarni8c5f34f2012-09-14 17:13:38 -07001173 case HAL_PARAM_VENC_SYNC_FRAME_SEQUENCE_HEADER:
1174 {
1175 struct hfi_enable *hfi;
1176 pkt->rg_property_data[0] =
1177 HFI_PROPERTY_PARAM_VENC_SYNC_FRAME_SEQUENCE_HEADER;
1178 hfi = (struct hfi_enable *) &pkt->rg_property_data[1];
1179 hfi->enable = ((struct hfi_enable *) pdata)->enable;
1180 pkt->size += sizeof(u32) * 2;
1181 break;
1182 }
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08001183 case HAL_CONFIG_VENC_REQUEST_IFRAME:
Ashray Kulkarni1ccbc912012-03-23 16:26:52 -07001184 pkt->rg_property_data[0] =
Ashray Kulkarnife72c452012-05-29 19:52:00 -07001185 HFI_PROPERTY_CONFIG_VENC_REQUEST_SYNC_FRAME;
Praneeth Paladugu951c02d2012-07-11 12:19:42 -07001186 pkt->size += sizeof(u32);
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08001187 break;
1188 case HAL_PARAM_VENC_MPEG4_SHORT_HEADER:
1189 break;
1190 case HAL_PARAM_VENC_MPEG4_AC_PREDICTION:
1191 break;
1192 case HAL_CONFIG_VENC_TARGET_BITRATE:
Ashray Kulkarni1ccbc912012-03-23 16:26:52 -07001193 {
1194 struct hfi_bitrate *hfi;
1195 pkt->rg_property_data[0] =
1196 HFI_PROPERTY_CONFIG_VENC_TARGET_BITRATE;
1197 hfi = (struct hfi_bitrate *) &pkt->rg_property_data[1];
Ashray Kulkarnife72c452012-05-29 19:52:00 -07001198 hfi->bit_rate = ((struct hal_bitrate *)pdata)->bit_rate;
1199 pkt->size += sizeof(u32) * 2;
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08001200 break;
Ashray Kulkarni1ccbc912012-03-23 16:26:52 -07001201 }
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08001202 case HAL_PARAM_PROFILE_LEVEL_CURRENT:
1203 {
Ashray Kulkarnife72c452012-05-29 19:52:00 -07001204 struct hfi_profile_level *hfi;
1205 struct hal_profile_level *prop =
1206 (struct hal_profile_level *) pdata;
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08001207 pkt->rg_property_data[0] =
1208 HFI_PROPERTY_PARAM_PROFILE_LEVEL_CURRENT;
Ashray Kulkarnife72c452012-05-29 19:52:00 -07001209 hfi = (struct hfi_profile_level *)
1210 &pkt->rg_property_data[1];
1211 hfi->level = (u32) prop->level;
1212 hfi->profile = prop->profile;
1213 if (!hfi->profile)
1214 hfi->profile = HFI_H264_PROFILE_HIGH;
1215 if (!hfi->level)
1216 hfi->level = 1;
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08001217 pkt->size += sizeof(u32) + sizeof(struct hfi_profile_level);
1218 break;
1219 }
1220 case HAL_PARAM_VENC_H264_ENTROPY_CONTROL:
Ashray Kulkarni1ccbc912012-03-23 16:26:52 -07001221 {
1222 struct hfi_h264_entropy_control *hfi;
Ashray Kulkarnife72c452012-05-29 19:52:00 -07001223 struct hal_h264_entropy_control *prop =
1224 (struct hal_h264_entropy_control *) pdata;
Ashray Kulkarni1ccbc912012-03-23 16:26:52 -07001225 pkt->rg_property_data[0] =
1226 HFI_PROPERTY_PARAM_VENC_H264_ENTROPY_CONTROL;
1227 hfi = (struct hfi_h264_entropy_control *)
1228 &pkt->rg_property_data[1];
Ashray Kulkarnife72c452012-05-29 19:52:00 -07001229 switch (prop->entropy_mode) {
1230 case HAL_H264_ENTROPY_CAVLC:
1231 hfi->cabac_model = HFI_H264_ENTROPY_CAVLC;
1232 break;
1233 case HAL_H264_ENTROPY_CABAC:
1234 hfi->cabac_model = HFI_H264_ENTROPY_CABAC;
1235 switch (prop->cabac_model) {
1236 case HAL_H264_CABAC_MODEL_0:
1237 hfi->cabac_model = HFI_H264_CABAC_MODEL_0;
1238 break;
1239 case HAL_H264_CABAC_MODEL_1:
1240 hfi->cabac_model = HFI_H264_CABAC_MODEL_1;
1241 break;
1242 case HAL_H264_CABAC_MODEL_2:
1243 hfi->cabac_model = HFI_H264_CABAC_MODEL_2;
1244 break;
1245 default:
Blaine Dietrichf1a7cff2012-07-23 12:14:18 -07001246 dprintk(VIDC_ERR,
1247 "Invalid cabac model 0x%x",
1248 prop->entropy_mode);
Ashray Kulkarnife72c452012-05-29 19:52:00 -07001249 break;
1250 }
1251 break;
1252 default:
Blaine Dietrichf1a7cff2012-07-23 12:14:18 -07001253 dprintk(VIDC_ERR,
1254 "Invalid entropy selected: 0x%x",
Ashray Kulkarnife72c452012-05-29 19:52:00 -07001255 prop->cabac_model);
1256 break;
1257 }
Ashray Kulkarni1ccbc912012-03-23 16:26:52 -07001258 pkt->size += sizeof(u32) + sizeof(
1259 struct hfi_h264_entropy_control);
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08001260 break;
Ashray Kulkarni1ccbc912012-03-23 16:26:52 -07001261 }
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08001262 case HAL_PARAM_VENC_RATE_CONTROL:
Ashray Kulkarni1ccbc912012-03-23 16:26:52 -07001263 {
Ashray Kulkarnib6734502012-08-24 13:00:22 -07001264 u32 *rc;
Ashray Kulkarni1ccbc912012-03-23 16:26:52 -07001265 pkt->rg_property_data[0] =
1266 HFI_PROPERTY_PARAM_VENC_RATE_CONTROL;
Ashray Kulkarnib6734502012-08-24 13:00:22 -07001267 rc = (u32 *)pdata;
1268 switch ((enum hal_rate_control) *rc) {
Ashray Kulkarnife72c452012-05-29 19:52:00 -07001269 case HAL_RATE_CONTROL_OFF:
1270 pkt->rg_property_data[1] = HFI_RATE_CONTROL_OFF;
1271 break;
1272 case HAL_RATE_CONTROL_CBR_CFR:
1273 pkt->rg_property_data[1] = HFI_RATE_CONTROL_CBR_CFR;
1274 break;
1275 case HAL_RATE_CONTROL_CBR_VFR:
1276 pkt->rg_property_data[1] = HFI_RATE_CONTROL_CBR_VFR;
1277 break;
1278 case HAL_RATE_CONTROL_VBR_CFR:
1279 pkt->rg_property_data[1] = HFI_RATE_CONTROL_VBR_CFR;
1280 break;
1281 case HAL_RATE_CONTROL_VBR_VFR:
1282 pkt->rg_property_data[1] = HFI_RATE_CONTROL_VBR_VFR;
1283 break;
1284 default:
Blaine Dietrichf1a7cff2012-07-23 12:14:18 -07001285 dprintk(VIDC_ERR, "Invalid Rate control setting: 0x%x",
Ashray Kulkarnife72c452012-05-29 19:52:00 -07001286 (int) pdata);
1287 break;
1288 }
1289 pkt->size += sizeof(u32) * 2;
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08001290 break;
Ashray Kulkarni1ccbc912012-03-23 16:26:52 -07001291 }
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08001292 case HAL_PARAM_VENC_MPEG4_TIME_RESOLUTION:
Ashray Kulkarni1ccbc912012-03-23 16:26:52 -07001293 {
1294 struct hfi_mpeg4_time_resolution *hfi;
1295 pkt->rg_property_data[0] =
1296 HFI_PROPERTY_PARAM_VENC_MPEG4_TIME_RESOLUTION;
1297 hfi = (struct hfi_mpeg4_time_resolution *)
1298 &pkt->rg_property_data[1];
1299 hfi->time_increment_resolution =
1300 ((struct hal_mpeg4_time_resolution *)pdata)->
1301 time_increment_resolution;
Ashray Kulkarnife72c452012-05-29 19:52:00 -07001302 pkt->size += sizeof(u32) * 2;
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08001303 break;
Ashray Kulkarni1ccbc912012-03-23 16:26:52 -07001304 }
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08001305 case HAL_PARAM_VENC_MPEG4_HEADER_EXTENSION:
Ashray Kulkarni1ccbc912012-03-23 16:26:52 -07001306 {
1307 struct hfi_mpeg4_header_extension *hfi;
1308 pkt->rg_property_data[0] =
1309 HFI_PROPERTY_PARAM_VENC_MPEG4_HEADER_EXTENSION;
1310 hfi = (struct hfi_mpeg4_header_extension *)
Ashray Kulkarnife72c452012-05-29 19:52:00 -07001311 &pkt->rg_property_data[1];
Ashray Kulkarni1ccbc912012-03-23 16:26:52 -07001312 hfi->header_extension = (u32) pdata;
Ashray Kulkarnife72c452012-05-29 19:52:00 -07001313 pkt->size += sizeof(u32) * 2;
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08001314 break;
Ashray Kulkarni1ccbc912012-03-23 16:26:52 -07001315 }
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08001316 case HAL_PARAM_VENC_H264_DEBLOCK_CONTROL:
Ashray Kulkarni1ccbc912012-03-23 16:26:52 -07001317 {
1318 struct hfi_h264_db_control *hfi;
Ashray Kulkarnife72c452012-05-29 19:52:00 -07001319 struct hal_h264_db_control *prop =
1320 (struct hal_h264_db_control *) pdata;
Ashray Kulkarni1ccbc912012-03-23 16:26:52 -07001321 pkt->rg_property_data[0] =
1322 HFI_PROPERTY_PARAM_VENC_H264_DEBLOCK_CONTROL;
1323 hfi = (struct hfi_h264_db_control *) &pkt->rg_property_data[1];
Ashray Kulkarnife72c452012-05-29 19:52:00 -07001324 switch (prop->mode) {
1325 case HAL_H264_DB_MODE_DISABLE:
1326 hfi->mode = HFI_H264_DB_MODE_DISABLE;
1327 break;
1328 case HAL_H264_DB_MODE_SKIP_SLICE_BOUNDARY:
1329 hfi->mode = HFI_H264_DB_MODE_SKIP_SLICE_BOUNDARY;
1330 break;
1331 case HAL_H264_DB_MODE_ALL_BOUNDARY:
1332 hfi->mode = HFI_H264_DB_MODE_ALL_BOUNDARY;
1333 break;
1334 default:
Blaine Dietrichf1a7cff2012-07-23 12:14:18 -07001335 dprintk(VIDC_ERR, "Invalid deblocking mode: 0x%x",
Ashray Kulkarnife72c452012-05-29 19:52:00 -07001336 prop->mode);
1337 break;
1338 }
1339 hfi->slice_alpha_offset = prop->slice_alpha_offset;
1340 hfi->slice_beta_offset = prop->slice_beta_offset;
Ashray Kulkarni1ccbc912012-03-23 16:26:52 -07001341 pkt->size += sizeof(u32) +
1342 sizeof(struct hfi_h264_db_control);
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08001343 break;
Ashray Kulkarni1ccbc912012-03-23 16:26:52 -07001344 }
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08001345 case HAL_PARAM_VENC_SESSION_QP:
Ashray Kulkarni1ccbc912012-03-23 16:26:52 -07001346 {
1347 struct hfi_quantization *hfi;
1348 pkt->rg_property_data[0] =
1349 HFI_PROPERTY_PARAM_VENC_SESSION_QP;
1350 hfi = (struct hfi_quantization *) &pkt->rg_property_data[1];
1351 memcpy(hfi, (struct hfi_quantization *) pdata,
1352 sizeof(struct hfi_quantization));
1353 pkt->size += sizeof(u32) + sizeof(struct hfi_quantization);
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08001354 break;
Ashray Kulkarni1ccbc912012-03-23 16:26:52 -07001355 }
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08001356 case HAL_CONFIG_VENC_INTRA_PERIOD:
Ashray Kulkarni1ccbc912012-03-23 16:26:52 -07001357 {
1358 struct hfi_intra_period *hfi;
1359 pkt->rg_property_data[0] =
1360 HFI_PROPERTY_CONFIG_VENC_INTRA_PERIOD;
1361 hfi = (struct hfi_intra_period *) &pkt->rg_property_data[1];
1362 memcpy(hfi, (struct hfi_intra_period *) pdata,
1363 sizeof(struct hfi_intra_period));
1364 pkt->size += sizeof(u32) + sizeof(struct hfi_intra_period);
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08001365 break;
Ashray Kulkarni1ccbc912012-03-23 16:26:52 -07001366 }
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08001367 case HAL_CONFIG_VENC_IDR_PERIOD:
Ashray Kulkarni1ccbc912012-03-23 16:26:52 -07001368 {
1369 struct hfi_idr_period *hfi;
1370 pkt->rg_property_data[0] = HFI_PROPERTY_CONFIG_VENC_IDR_PERIOD;
1371 hfi = (struct hfi_idr_period *) &pkt->rg_property_data[1];
1372 hfi->idr_period = ((struct hfi_idr_period *) pdata)->idr_period;
Ashray Kulkarnife72c452012-05-29 19:52:00 -07001373 pkt->size += sizeof(u32) * 2;
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08001374 break;
Ashray Kulkarni1ccbc912012-03-23 16:26:52 -07001375 }
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08001376 case HAL_CONFIG_VPE_OPERATIONS:
1377 break;
1378 case HAL_PARAM_VENC_INTRA_REFRESH:
Ashray Kulkarni1ccbc912012-03-23 16:26:52 -07001379 {
1380 struct hfi_intra_refresh *hfi;
Ashray Kulkarnife72c452012-05-29 19:52:00 -07001381 struct hal_intra_refresh *prop =
1382 (struct hal_intra_refresh *) pdata;
Ashray Kulkarni1ccbc912012-03-23 16:26:52 -07001383 pkt->rg_property_data[0] =
1384 HFI_PROPERTY_PARAM_VENC_INTRA_REFRESH;
1385 hfi = (struct hfi_intra_refresh *) &pkt->rg_property_data[1];
Ashray Kulkarnife72c452012-05-29 19:52:00 -07001386 switch (prop->mode) {
1387 case HAL_INTRA_REFRESH_NONE:
1388 hfi->mode = HFI_INTRA_REFRESH_NONE;
1389 break;
1390 case HAL_INTRA_REFRESH_ADAPTIVE:
1391 hfi->mode = HFI_INTRA_REFRESH_ADAPTIVE;
1392 break;
1393 case HAL_INTRA_REFRESH_CYCLIC:
1394 hfi->mode = HFI_INTRA_REFRESH_CYCLIC;
1395 break;
1396 case HAL_INTRA_REFRESH_CYCLIC_ADAPTIVE:
1397 hfi->mode = HFI_INTRA_REFRESH_CYCLIC_ADAPTIVE;
1398 break;
1399 case HAL_INTRA_REFRESH_RANDOM:
1400 hfi->mode = HFI_INTRA_REFRESH_RANDOM;
1401 break;
1402 default:
Blaine Dietrichf1a7cff2012-07-23 12:14:18 -07001403 dprintk(VIDC_ERR, "Invalid intra refresh setting: 0x%x",
Ashray Kulkarnife72c452012-05-29 19:52:00 -07001404 prop->mode);
1405 break;
1406 }
1407 hfi->air_mbs = prop->air_mbs;
1408 hfi->air_ref = prop->air_ref;
1409 hfi->cir_mbs = prop->cir_mbs;
Ashray Kulkarni1ccbc912012-03-23 16:26:52 -07001410 pkt->size += sizeof(u32) + sizeof(struct hfi_intra_refresh);
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08001411 break;
Ashray Kulkarni1ccbc912012-03-23 16:26:52 -07001412 }
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08001413 case HAL_PARAM_VENC_MULTI_SLICE_CONTROL:
Ashray Kulkarni1ccbc912012-03-23 16:26:52 -07001414 {
1415 struct hfi_multi_slice_control *hfi;
Ashray Kulkarnife72c452012-05-29 19:52:00 -07001416 struct hal_multi_slice_control *prop =
1417 (struct hal_multi_slice_control *) pdata;
Ashray Kulkarni1ccbc912012-03-23 16:26:52 -07001418 pkt->rg_property_data[0] =
1419 HFI_PROPERTY_PARAM_VENC_MULTI_SLICE_CONTROL;
1420 hfi = (struct hfi_multi_slice_control *)
Ashray Kulkarnife72c452012-05-29 19:52:00 -07001421 &pkt->rg_property_data[1];
1422 switch (prop->multi_slice) {
1423 case HAL_MULTI_SLICE_OFF:
1424 hfi->multi_slice = HFI_MULTI_SLICE_OFF;
1425 break;
1426 case HAL_MULTI_SLICE_GOB:
1427 hfi->multi_slice = HFI_MULTI_SLICE_GOB;
1428 break;
1429 case HAL_MULTI_SLICE_BY_MB_COUNT:
1430 hfi->multi_slice = HFI_MULTI_SLICE_BY_MB_COUNT;
1431 break;
1432 case HAL_MULTI_SLICE_BY_BYTE_COUNT:
1433 hfi->multi_slice = HFI_MULTI_SLICE_BY_BYTE_COUNT;
1434 break;
1435 default:
Blaine Dietrichf1a7cff2012-07-23 12:14:18 -07001436 dprintk(VIDC_ERR, "Invalid slice settings: 0x%x",
Ashray Kulkarnife72c452012-05-29 19:52:00 -07001437 prop->multi_slice);
1438 break;
1439 }
Ashray Kulkarni6a8803f2012-10-09 18:41:49 -07001440 hfi->slice_size = prop->slice_size;
Ashray Kulkarni1ccbc912012-03-23 16:26:52 -07001441 pkt->size += sizeof(u32) + sizeof(struct
Ashray Kulkarnife72c452012-05-29 19:52:00 -07001442 hfi_multi_slice_control);
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08001443 break;
Ashray Kulkarni1ccbc912012-03-23 16:26:52 -07001444 }
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08001445 case HAL_CONFIG_VPE_DEINTERLACE:
1446 break;
1447 case HAL_SYS_DEBUG_CONFIG:
Ashray Kulkarni1ccbc912012-03-23 16:26:52 -07001448 {
1449 struct hfi_debug_config *hfi;
1450 pkt->rg_property_data[0] = HFI_PROPERTY_SYS_DEBUG_CONFIG;
1451 hfi = (struct hfi_debug_config *) &pkt->rg_property_data[1];
Ashray Kulkarnife72c452012-05-29 19:52:00 -07001452 hfi->debug_config = ((struct hal_debug_config *)
1453 pdata)->debug_config;
Ashray Kulkarni1ccbc912012-03-23 16:26:52 -07001454 pkt->size = sizeof(struct hfi_cmd_sys_set_property_packet) +
1455 sizeof(struct hfi_debug_config);
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08001456 break;
Ashray Kulkarni1ccbc912012-03-23 16:26:52 -07001457 }
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08001458 /* FOLLOWING PROPERTIES ARE NOT IMPLEMENTED IN CORE YET */
1459 case HAL_CONFIG_BUFFER_REQUIREMENTS:
1460 case HAL_CONFIG_PRIORITY:
1461 case HAL_CONFIG_BATCH_INFO:
1462 case HAL_PARAM_METADATA_PASS_THROUGH:
1463 case HAL_SYS_IDLE_INDICATOR:
1464 case HAL_PARAM_UNCOMPRESSED_FORMAT_SUPPORTED:
1465 case HAL_PARAM_INTERLACE_FORMAT_SUPPORTED:
1466 case HAL_PARAM_CHROMA_SITE:
1467 case HAL_PARAM_PROPERTIES_SUPPORTED:
1468 case HAL_PARAM_PROFILE_LEVEL_SUPPORTED:
1469 case HAL_PARAM_CAPABILITY_SUPPORTED:
1470 case HAL_PARAM_NAL_STREAM_FORMAT_SUPPORTED:
1471 case HAL_PARAM_MULTI_VIEW_FORMAT:
1472 case HAL_PARAM_MAX_SEQUENCE_HEADER_SIZE:
1473 case HAL_PARAM_CODEC_SUPPORTED:
1474 case HAL_PARAM_VDEC_MULTI_VIEW_SELECT:
1475 case HAL_PARAM_VDEC_MB_QUANTIZATION:
1476 case HAL_PARAM_VDEC_NUM_CONCEALED_MB:
1477 case HAL_PARAM_VDEC_H264_ENTROPY_SWITCHING:
1478 case HAL_PARAM_VENC_SLICE_DELIVERY_MODE:
1479 case HAL_PARAM_VENC_MPEG4_DATA_PARTITIONING:
1480
1481 case HAL_CONFIG_BUFFER_COUNT_ACTUAL:
1482 case HAL_CONFIG_VDEC_MULTI_STREAM:
1483 case HAL_PARAM_VENC_MULTI_SLICE_INFO:
1484 case HAL_CONFIG_VENC_TIMESTAMP_SCALE:
1485 case HAL_PARAM_VENC_LOW_LATENCY:
1486 default:
Blaine Dietrichf1a7cff2012-07-23 12:14:18 -07001487 dprintk(VIDC_INFO, "DEFAULT: Calling 0x%x", ptype);
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08001488 break;
1489 }
1490 if (vidc_hal_iface_cmdq_write(session->device, pkt))
1491 return -ENOTEMPTY;
1492 return 0;
1493}
1494
1495int vidc_hal_session_get_property(void *sess,
1496 enum hal_property ptype, void *pdata)
1497{
1498 struct hal_session *session;
1499
1500 if (!sess || !pdata) {
Blaine Dietrichf1a7cff2012-07-23 12:14:18 -07001501 dprintk(VIDC_ERR, "Invalid Params in ");
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08001502 return -EINVAL;
1503 } else {
1504 session = sess;
1505 }
Blaine Dietrichf1a7cff2012-07-23 12:14:18 -07001506 dprintk(VIDC_INFO, "IN func: , with property id: %d", ptype);
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08001507
1508 switch (ptype) {
1509 case HAL_CONFIG_FRAME_RATE:
1510 break;
1511 case HAL_PARAM_UNCOMPRESSED_FORMAT_SELECT:
1512 break;
1513 case HAL_PARAM_UNCOMPRESSED_PLANE_ACTUAL_CONSTRAINTS_INFO:
1514 break;
1515 case HAL_PARAM_UNCOMPRESSED_PLANE_ACTUAL_INFO:
1516 break;
1517 case HAL_PARAM_EXTRA_DATA_HEADER_CONFIG:
1518 break;
1519 case HAL_PARAM_FRAME_SIZE:
1520 break;
1521 case HAL_CONFIG_REALTIME:
1522 break;
1523 case HAL_PARAM_BUFFER_COUNT_ACTUAL:
1524 break;
1525 case HAL_PARAM_NAL_STREAM_FORMAT_SELECT:
1526 break;
1527 case HAL_PARAM_VDEC_OUTPUT_ORDER:
1528 break;
1529 case HAL_PARAM_VDEC_PICTURE_TYPE_DECODE:
1530 break;
1531 case HAL_PARAM_VDEC_OUTPUT2_KEEP_ASPECT_RATIO:
1532 break;
1533 case HAL_CONFIG_VDEC_POST_LOOP_DEBLOCKER:
1534 break;
1535 case HAL_PARAM_VDEC_MULTI_STREAM:
1536 break;
1537 case HAL_PARAM_VDEC_DISPLAY_PICTURE_BUFFER_COUNT:
1538 break;
1539 case HAL_PARAM_DIVX_FORMAT:
1540 break;
1541 case HAL_CONFIG_VDEC_MB_ERROR_MAP_REPORTING:
1542 break;
1543 case HAL_PARAM_VDEC_CONTINUE_DATA_TRANSFER:
1544 break;
1545 case HAL_CONFIG_VDEC_MB_ERROR_MAP:
1546 break;
1547 case HAL_CONFIG_VENC_REQUEST_IFRAME:
1548 break;
1549 case HAL_PARAM_VENC_MPEG4_SHORT_HEADER:
1550 break;
1551 case HAL_PARAM_VENC_MPEG4_AC_PREDICTION:
1552 break;
1553 case HAL_CONFIG_VENC_TARGET_BITRATE:
1554 break;
1555 case HAL_PARAM_PROFILE_LEVEL_CURRENT:
1556 break;
1557 case HAL_PARAM_VENC_H264_ENTROPY_CONTROL:
1558 break;
1559 case HAL_PARAM_VENC_RATE_CONTROL:
1560 break;
1561 case HAL_PARAM_VENC_MPEG4_TIME_RESOLUTION:
1562 break;
1563 case HAL_PARAM_VENC_MPEG4_HEADER_EXTENSION:
1564 break;
1565 case HAL_PARAM_VENC_H264_DEBLOCK_CONTROL:
1566 break;
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08001567 case HAL_PARAM_VENC_SESSION_QP:
1568 break;
1569 case HAL_CONFIG_VENC_INTRA_PERIOD:
1570 break;
1571 case HAL_CONFIG_VENC_IDR_PERIOD:
1572 break;
1573 case HAL_CONFIG_VPE_OPERATIONS:
1574 break;
1575 case HAL_PARAM_VENC_INTRA_REFRESH:
1576 break;
1577 case HAL_PARAM_VENC_MULTI_SLICE_CONTROL:
1578 break;
1579 case HAL_CONFIG_VPE_DEINTERLACE:
1580 break;
1581 case HAL_SYS_DEBUG_CONFIG:
1582 break;
1583 /*FOLLOWING PROPERTIES ARE NOT IMPLEMENTED IN CORE YET*/
1584 case HAL_CONFIG_BUFFER_REQUIREMENTS:
1585 case HAL_CONFIG_PRIORITY:
1586 case HAL_CONFIG_BATCH_INFO:
1587 case HAL_PARAM_METADATA_PASS_THROUGH:
1588 case HAL_SYS_IDLE_INDICATOR:
1589 case HAL_PARAM_UNCOMPRESSED_FORMAT_SUPPORTED:
1590 case HAL_PARAM_INTERLACE_FORMAT_SUPPORTED:
1591 case HAL_PARAM_CHROMA_SITE:
1592 case HAL_PARAM_PROPERTIES_SUPPORTED:
1593 case HAL_PARAM_PROFILE_LEVEL_SUPPORTED:
1594 case HAL_PARAM_CAPABILITY_SUPPORTED:
1595 case HAL_PARAM_NAL_STREAM_FORMAT_SUPPORTED:
1596 case HAL_PARAM_MULTI_VIEW_FORMAT:
1597 case HAL_PARAM_MAX_SEQUENCE_HEADER_SIZE:
1598 case HAL_PARAM_CODEC_SUPPORTED:
1599 case HAL_PARAM_VDEC_MULTI_VIEW_SELECT:
1600 case HAL_PARAM_VDEC_MB_QUANTIZATION:
1601 case HAL_PARAM_VDEC_NUM_CONCEALED_MB:
1602 case HAL_PARAM_VDEC_H264_ENTROPY_SWITCHING:
1603 case HAL_PARAM_VENC_SLICE_DELIVERY_MODE:
1604 case HAL_PARAM_VENC_MPEG4_DATA_PARTITIONING:
1605
1606 case HAL_CONFIG_BUFFER_COUNT_ACTUAL:
1607 case HAL_CONFIG_VDEC_MULTI_STREAM:
1608 case HAL_PARAM_VENC_MULTI_SLICE_INFO:
1609 case HAL_CONFIG_VENC_TIMESTAMP_SCALE:
1610 case HAL_PARAM_VENC_LOW_LATENCY:
1611 default:
Blaine Dietrichf1a7cff2012-07-23 12:14:18 -07001612 dprintk(VIDC_INFO, "DEFAULT: Calling 0x%x", ptype);
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08001613 break;
1614 }
1615 return 0;
1616}
1617
1618void *vidc_hal_session_init(void *device, u32 session_id,
1619 enum hal_domain session_type, enum hal_video_codec codec_type)
1620{
1621 struct hfi_cmd_sys_session_init_packet pkt;
1622 struct hal_session *new_session;
1623 struct hal_device *dev;
1624
1625 if (device) {
1626 dev = device;
1627 } else {
Ashray Kulkarni000b3822012-10-11 18:20:58 -07001628 dprintk(VIDC_ERR, "invalid device");
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08001629 return NULL;
1630 }
1631
1632 new_session = (struct hal_session *)
1633 kzalloc(sizeof(struct hal_session), GFP_KERNEL);
1634 new_session->session_id = (u32) session_id;
1635 if (session_type == 1)
1636 new_session->is_decoder = 0;
1637 else if (session_type == 2)
1638 new_session->is_decoder = 1;
1639 new_session->device = dev;
1640 list_add_tail(&new_session->list, &dev->sess_head);
1641 pkt.size = sizeof(struct hfi_cmd_sys_session_init_packet);
Ashray Kulkarnife72c452012-05-29 19:52:00 -07001642 pkt.packet_type = HFI_CMD_SYS_SESSION_INIT;
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08001643 pkt.session_id = (u32) new_session;
1644 pkt.session_domain = session_type;
1645 pkt.session_codec = codec_type;
1646 if (vidc_hal_iface_cmdq_write(dev, &pkt))
1647 return NULL;
1648 return (void *) new_session;
1649}
1650
1651static int vidc_hal_send_session_cmd(void *session_id,
Ashray Kulkarnife72c452012-05-29 19:52:00 -07001652 int pkt_type)
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08001653{
1654 struct vidc_hal_session_cmd_pkt pkt;
1655 int rc = 0;
1656 struct hal_session *session;
1657
1658 if (session_id) {
1659 session = session_id;
1660 } else {
Ashray Kulkarni000b3822012-10-11 18:20:58 -07001661 dprintk(VIDC_ERR, "invalid session");
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08001662 return -ENODEV;
1663 }
1664
1665 pkt.size = sizeof(struct vidc_hal_session_cmd_pkt);
1666 pkt.packet_type = pkt_type;
1667 pkt.session_id = (u32) session;
1668
1669 if (vidc_hal_iface_cmdq_write(session->device, &pkt))
1670 rc = -ENOTEMPTY;
1671 return rc;
1672}
1673
1674int vidc_hal_session_end(void *session)
1675{
1676 return vidc_hal_send_session_cmd(session,
1677 HFI_CMD_SYS_SESSION_END);
1678}
1679
1680int vidc_hal_session_abort(void *session)
1681{
1682 return vidc_hal_send_session_cmd(session,
1683 HFI_CMD_SYS_SESSION_ABORT);
1684}
1685
1686int vidc_hal_session_set_buffers(void *sess,
1687 struct vidc_buffer_addr_info *buffer_info)
1688{
Ashray Kulkarnife72c452012-05-29 19:52:00 -07001689 u32 buffer;
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08001690 struct hfi_cmd_session_set_buffers_packet *pkt;
1691 u8 packet[VIDC_IFACEQ_VAR_LARGE_PKT_SIZE];
1692 int rc = 0;
1693 u16 i;
1694 struct hal_session *session;
1695
1696 if (!sess || !buffer_info) {
Ashray Kulkarni000b3822012-10-11 18:20:58 -07001697 dprintk(VIDC_ERR, "Invalid Params");
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08001698 return -EINVAL;
1699 } else {
1700 session = sess;
1701 }
1702
1703 if (buffer_info->buffer_type == HAL_BUFFER_INPUT)
1704 return 0;
1705
1706 pkt = (struct hfi_cmd_session_set_buffers_packet *)packet;
1707
1708 pkt->size = sizeof(struct hfi_cmd_session_set_buffers_packet) +
1709 ((buffer_info->num_buffers - 1) * sizeof(u32));
1710 pkt->packet_type = HFI_CMD_SESSION_SET_BUFFERS;
1711 pkt->session_id = (u32) session;
1712 pkt->buffer_mode = HFI_BUFFER_MODE_STATIC;
1713 pkt->buffer_size = buffer_info->buffer_size;
1714 pkt->min_buffer_size = buffer_info->buffer_size;
1715 pkt->num_buffers = buffer_info->num_buffers;
1716
1717 if ((buffer_info->buffer_type == HAL_BUFFER_OUTPUT) ||
1718 (buffer_info->buffer_type == HAL_BUFFER_OUTPUT2)) {
1719 struct hfi_buffer_info *buff;
Ashray Kulkarnife72c452012-05-29 19:52:00 -07001720 pkt->extra_data_size = buffer_info->extradata_size;
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08001721 pkt->size = sizeof(struct hfi_cmd_session_set_buffers_packet) -
1722 sizeof(u32) + ((buffer_info->num_buffers) *
1723 sizeof(struct hfi_buffer_info));
1724 buff = (struct hfi_buffer_info *) pkt->rg_buffer_info;
1725 for (i = 0; i < pkt->num_buffers; i++) {
1726 buff->buffer_addr =
1727 buffer_info->align_device_addr;
Ashray Kulkarnife72c452012-05-29 19:52:00 -07001728 buff->extra_data_addr =
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08001729 buffer_info->extradata_addr;
1730 }
1731 } else {
Ashray Kulkarnife72c452012-05-29 19:52:00 -07001732 pkt->extra_data_size = 0;
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08001733 pkt->size = sizeof(struct hfi_cmd_session_set_buffers_packet) +
1734 ((buffer_info->num_buffers - 1) * sizeof(u32));
1735 for (i = 0; i < pkt->num_buffers; i++)
1736 pkt->rg_buffer_info[i] =
1737 buffer_info->align_device_addr;
1738 }
Ashray Kulkarnife72c452012-05-29 19:52:00 -07001739 buffer = get_hfi_buffer(buffer_info->buffer_type);
1740 if (buffer)
1741 pkt->buffer_type = buffer;
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08001742 else
Ashray Kulkarnife72c452012-05-29 19:52:00 -07001743 return -EINVAL;
Blaine Dietrichf1a7cff2012-07-23 12:14:18 -07001744 dprintk(VIDC_INFO, "set buffers: 0x%x", buffer_info->buffer_type);
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08001745 if (vidc_hal_iface_cmdq_write(session->device, pkt))
1746 rc = -ENOTEMPTY;
1747 return rc;
1748}
1749
1750int vidc_hal_session_release_buffers(void *sess,
1751 struct vidc_buffer_addr_info *buffer_info)
1752{
Ashray Kulkarnife72c452012-05-29 19:52:00 -07001753 u32 buffer;
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08001754 struct hfi_cmd_session_release_buffer_packet *pkt;
1755 u8 packet[VIDC_IFACEQ_VAR_LARGE_PKT_SIZE];
1756 int rc = 0;
1757 u32 i;
1758 struct hal_session *session;
1759
1760 if (!sess || !buffer_info) {
Ashray Kulkarni000b3822012-10-11 18:20:58 -07001761 dprintk(VIDC_ERR, "Invalid Params");
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08001762 return -EINVAL;
1763 } else {
1764 session = sess;
1765 }
1766
1767 if (buffer_info->buffer_type == HAL_BUFFER_INPUT)
1768 return 0;
1769
1770 pkt = (struct hfi_cmd_session_release_buffer_packet *) packet;
1771 pkt->size = sizeof(struct hfi_cmd_session_release_buffer_packet) +
1772 ((buffer_info->num_buffers - 1) * sizeof(u32));
1773 pkt->packet_type = HFI_CMD_SESSION_RELEASE_BUFFERS;
1774 pkt->session_id = (u32) session;
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08001775 pkt->buffer_size = buffer_info->buffer_size;
1776 pkt->num_buffers = buffer_info->num_buffers;
1777
1778 if ((buffer_info->buffer_type == HAL_BUFFER_OUTPUT) ||
1779 (buffer_info->buffer_type == HAL_BUFFER_OUTPUT2)) {
1780 struct hfi_buffer_info *buff;
1781 buff = (struct hfi_buffer_info *) pkt->rg_buffer_info;
1782 for (i = 0; i < pkt->num_buffers; i++) {
1783 buff->buffer_addr =
1784 buffer_info->align_device_addr;
Ashray Kulkarnife72c452012-05-29 19:52:00 -07001785 buff->extra_data_addr =
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08001786 buffer_info->extradata_addr;
1787 }
Ashray Kulkarnife72c452012-05-29 19:52:00 -07001788 pkt->extra_data_size = buffer_info->extradata_size;
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08001789 pkt->size = sizeof(struct hfi_cmd_session_set_buffers_packet) -
1790 sizeof(u32) + ((buffer_info->num_buffers) *
1791 sizeof(struct hfi_buffer_info));
1792 } else {
1793 for (i = 0; i < pkt->num_buffers; i++)
1794 pkt->rg_buffer_info[i] =
1795 buffer_info->align_device_addr;
Ashray Kulkarnife72c452012-05-29 19:52:00 -07001796 pkt->extra_data_size = 0;
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08001797 pkt->size = sizeof(struct hfi_cmd_session_set_buffers_packet) +
1798 ((buffer_info->num_buffers - 1) * sizeof(u32));
1799 }
Ashray Kulkarnife72c452012-05-29 19:52:00 -07001800 buffer = get_hfi_buffer(buffer_info->buffer_type);
1801 if (buffer)
1802 pkt->buffer_type = buffer;
1803 else
1804 return -EINVAL;
Blaine Dietrichf1a7cff2012-07-23 12:14:18 -07001805 dprintk(VIDC_INFO, "Release buffers: 0x%x", buffer_info->buffer_type);
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08001806 if (vidc_hal_iface_cmdq_write(session->device, pkt))
1807 rc = -ENOTEMPTY;
1808 return rc;
1809}
1810
1811int vidc_hal_session_load_res(void *sess)
1812{
1813 return vidc_hal_send_session_cmd(sess,
1814 HFI_CMD_SESSION_LOAD_RESOURCES);
1815}
1816
1817int vidc_hal_session_release_res(void *sess)
1818{
1819 return vidc_hal_send_session_cmd(sess,
1820 HFI_CMD_SESSION_RELEASE_RESOURCES);
1821}
1822
1823int vidc_hal_session_start(void *sess)
1824{
1825 return vidc_hal_send_session_cmd(sess,
1826 HFI_CMD_SESSION_START);
1827}
1828
1829int vidc_hal_session_stop(void *sess)
1830{
1831 return vidc_hal_send_session_cmd(sess,
1832 HFI_CMD_SESSION_STOP);
1833}
1834
1835int vidc_hal_session_suspend(void *sess)
1836{
1837 return vidc_hal_send_session_cmd(sess,
1838 HFI_CMD_SESSION_SUSPEND);
1839}
1840
1841int vidc_hal_session_resume(void *sess)
1842{
1843 return vidc_hal_send_session_cmd(sess,
1844 HFI_CMD_SESSION_RESUME);
1845}
1846
1847int vidc_hal_session_etb(void *sess, struct vidc_frame_data *input_frame)
1848{
1849 int rc = 0;
1850 struct hal_session *session;
1851
1852 if (!sess || !input_frame) {
Ashray Kulkarni000b3822012-10-11 18:20:58 -07001853 dprintk(VIDC_ERR, "Invalid Params");
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08001854 return -EINVAL;
1855 } else {
1856 session = sess;
1857 }
1858
1859 if (session->is_decoder) {
1860 struct hfi_cmd_session_empty_buffer_compressed_packet pkt;
1861 pkt.size = sizeof(
1862 struct hfi_cmd_session_empty_buffer_compressed_packet);
1863 pkt.packet_type = HFI_CMD_SESSION_EMPTY_BUFFER;
1864 pkt.session_id = (u32) session;
Ashray Kulkarnife72c452012-05-29 19:52:00 -07001865 pkt.time_stamp_hi = (int) (((u64)input_frame->timestamp) >> 32);
1866 pkt.time_stamp_lo = (int) input_frame->timestamp;
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08001867 pkt.flags = input_frame->flags;
1868 pkt.mark_target = input_frame->mark_target;
1869 pkt.mark_data = input_frame->mark_data;
1870 pkt.offset = input_frame->offset;
1871 pkt.alloc_len = input_frame->alloc_len;
1872 pkt.filled_len = input_frame->filled_len;
1873 pkt.input_tag = input_frame->clnt_data;
1874 pkt.packet_buffer = (u8 *) input_frame->device_addr;
Blaine Dietrichf1a7cff2012-07-23 12:14:18 -07001875 dprintk(VIDC_DBG, "Q DECODER INPUT BUFFER");
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08001876 if (vidc_hal_iface_cmdq_write(session->device, &pkt))
1877 rc = -ENOTEMPTY;
1878 } else {
1879 struct hfi_cmd_session_empty_buffer_uncompressed_plane0_packet
1880 pkt;
1881 pkt.size = sizeof(struct
1882 hfi_cmd_session_empty_buffer_uncompressed_plane0_packet);
Ashray Kulkarnife72c452012-05-29 19:52:00 -07001883 pkt.packet_type = HFI_CMD_SESSION_EMPTY_BUFFER;
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08001884 pkt.session_id = (u32) session;
1885 pkt.view_id = 0;
Ashray Kulkarnife72c452012-05-29 19:52:00 -07001886 pkt.time_stamp_hi = (u32) (((u64)input_frame->timestamp) >> 32);
1887 pkt.time_stamp_lo = (u32) input_frame->timestamp;
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08001888 pkt.flags = input_frame->flags;
1889 pkt.mark_target = input_frame->mark_target;
1890 pkt.mark_data = input_frame->mark_data;
1891 pkt.offset = input_frame->offset;
1892 pkt.alloc_len = input_frame->alloc_len;
1893 pkt.filled_len = input_frame->filled_len;
1894 pkt.input_tag = input_frame->clnt_data;
1895 pkt.packet_buffer = (u8 *) input_frame->device_addr;
Blaine Dietrichf1a7cff2012-07-23 12:14:18 -07001896 dprintk(VIDC_DBG, "Q ENCODER INPUT BUFFER");
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08001897 if (vidc_hal_iface_cmdq_write(session->device, &pkt))
1898 rc = -ENOTEMPTY;
1899 }
1900 return rc;
1901}
1902
1903int vidc_hal_session_ftb(void *sess,
1904 struct vidc_frame_data *output_frame)
1905{
1906 struct hfi_cmd_session_fill_buffer_packet pkt;
1907 int rc = 0;
1908 struct hal_session *session;
1909
1910 if (!sess || !output_frame) {
Ashray Kulkarni000b3822012-10-11 18:20:58 -07001911 dprintk(VIDC_ERR, "Invalid Params");
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08001912 return -EINVAL;
1913 } else {
1914 session = sess;
1915 }
1916
1917 pkt.size = sizeof(struct hfi_cmd_session_fill_buffer_packet);
1918 pkt.packet_type = HFI_CMD_SESSION_FILL_BUFFER;
1919 pkt.session_id = (u32) session;
1920 if (output_frame->buffer_type == HAL_BUFFER_OUTPUT)
1921 pkt.stream_id = 0;
1922 else if (output_frame->buffer_type == HAL_BUFFER_OUTPUT2)
1923 pkt.stream_id = 1;
1924 pkt.packet_buffer = (u8 *) output_frame->device_addr;
1925 pkt.extra_data_buffer =
1926 (u8 *) output_frame->extradata_addr;
1927
Blaine Dietrichf1a7cff2012-07-23 12:14:18 -07001928 dprintk(VIDC_INFO, "### Q OUTPUT BUFFER ###");
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08001929 if (vidc_hal_iface_cmdq_write(session->device, &pkt))
1930 rc = -ENOTEMPTY;
1931 return rc;
1932}
1933
1934int vidc_hal_session_parse_seq_hdr(void *sess,
1935 struct vidc_seq_hdr *seq_hdr)
1936{
1937 struct hfi_cmd_session_parse_sequence_header_packet *pkt;
1938 int rc = 0;
1939 u8 packet[VIDC_IFACEQ_VAR_SMALL_PKT_SIZE];
1940 struct hal_session *session;
1941
1942 if (!sess || !seq_hdr) {
Ashray Kulkarni000b3822012-10-11 18:20:58 -07001943 dprintk(VIDC_ERR, "Invalid Params");
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08001944 return -EINVAL;
1945 } else {
1946 session = sess;
1947 }
1948
1949 pkt = (struct hfi_cmd_session_parse_sequence_header_packet *) packet;
1950 pkt->size = sizeof(struct hfi_cmd_session_parse_sequence_header_packet);
1951 pkt->packet_type = HFI_CMD_SESSION_PARSE_SEQUENCE_HEADER;
1952 pkt->session_id = (u32) session;
1953 pkt->header_len = seq_hdr->seq_hdr_len;
1954 pkt->packet_buffer = seq_hdr->seq_hdr;
1955
1956 if (vidc_hal_iface_cmdq_write(session->device, pkt))
1957 rc = -ENOTEMPTY;
1958 return rc;
1959}
1960
1961int vidc_hal_session_get_seq_hdr(void *sess,
1962 struct vidc_seq_hdr *seq_hdr)
1963{
1964 struct hfi_cmd_session_get_sequence_header_packet *pkt;
1965 int rc = 0;
1966 u8 packet[VIDC_IFACEQ_VAR_SMALL_PKT_SIZE];
1967 struct hal_session *session;
1968
1969 if (!sess || !seq_hdr) {
Ashray Kulkarni000b3822012-10-11 18:20:58 -07001970 dprintk(VIDC_ERR, "Invalid Params");
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08001971 return -EINVAL;
1972 } else {
1973 session = sess;
1974 }
1975
1976 pkt = (struct hfi_cmd_session_get_sequence_header_packet *) packet;
1977 pkt->size = sizeof(struct hfi_cmd_session_get_sequence_header_packet);
1978 pkt->packet_type = HFI_CMD_SESSION_GET_SEQUENCE_HEADER;
1979 pkt->session_id = (u32) session;
1980 pkt->buffer_len = seq_hdr->seq_hdr_len;
1981 pkt->packet_buffer = seq_hdr->seq_hdr;
1982
1983 if (vidc_hal_iface_cmdq_write(session->device, pkt))
1984 rc = -ENOTEMPTY;
1985 return rc;
1986}
1987
1988int vidc_hal_session_get_buf_req(void *sess)
1989{
1990 struct hfi_cmd_session_get_property_packet pkt;
1991 int rc = 0;
1992 struct hal_session *session;
1993
1994 if (sess) {
1995 session = sess;
1996 } else {
Ashray Kulkarni000b3822012-10-11 18:20:58 -07001997 dprintk(VIDC_ERR, "invalid session");
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08001998 return -ENODEV;
1999 }
2000
2001 pkt.size = sizeof(struct hfi_cmd_session_get_property_packet);
2002 pkt.packet_type = HFI_CMD_SESSION_GET_PROPERTY;
2003 pkt.session_id = (u32) session;
2004 pkt.num_properties = 1;
2005 pkt.rg_property_data[0] = HFI_PROPERTY_CONFIG_BUFFER_REQUIREMENTS;
2006 if (vidc_hal_iface_cmdq_write(session->device, &pkt))
2007 rc = -ENOTEMPTY;
2008 return rc;
2009}
2010
2011int vidc_hal_session_flush(void *sess, enum hal_flush flush_mode)
2012{
2013 struct hfi_cmd_session_flush_packet pkt;
2014 int rc = 0;
2015 struct hal_session *session;
2016
2017 if (sess) {
2018 session = sess;
2019 } else {
Ashray Kulkarni000b3822012-10-11 18:20:58 -07002020 dprintk(VIDC_ERR, "invalid session");
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08002021 return -ENODEV;
2022 }
2023
2024 pkt.size = sizeof(struct hfi_cmd_session_flush_packet);
2025 pkt.packet_type = HFI_CMD_SESSION_FLUSH;
2026 pkt.session_id = (u32) session;
Ashray Kulkarnife72c452012-05-29 19:52:00 -07002027 switch (flush_mode) {
2028 case HAL_FLUSH_INPUT:
2029 pkt.flush_type = HFI_FLUSH_INPUT;
2030 break;
2031 case HAL_FLUSH_OUTPUT:
2032 pkt.flush_type = HFI_FLUSH_OUTPUT;
2033 break;
2034 case HAL_FLUSH_OUTPUT2:
2035 pkt.flush_type = HFI_FLUSH_OUTPUT2;
2036 break;
2037 case HAL_FLUSH_ALL:
2038 pkt.flush_type = HFI_FLUSH_ALL;
2039 break;
2040 default:
Blaine Dietrichf1a7cff2012-07-23 12:14:18 -07002041 dprintk(VIDC_ERR, "Invalid flush mode: 0x%x\n", flush_mode);
Ashray Kulkarnife72c452012-05-29 19:52:00 -07002042 break;
2043 }
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08002044 if (vidc_hal_iface_cmdq_write(session->device, &pkt))
2045 rc = -ENOTEMPTY;
2046 return rc;
2047}
2048
2049static int vidc_hal_check_core_registered(
2050 struct hal_device_data core, u32 fw_addr,
2051 u32 reg_addr, u32 reg_size, u32 irq)
2052{
2053 struct hal_device *device;
2054 struct list_head *curr, *next;
2055
2056 if (core.dev_count) {
2057 list_for_each_safe(curr, next, &core.dev_head) {
2058 device = list_entry(curr, struct hal_device, list);
2059 if (device && device->hal_data->irq == irq &&
Vinay Kalia68398a42012-06-22 18:36:12 -07002060 (CONTAINS(device->hal_data->
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08002061 device_base_addr,
2062 FIRMWARE_SIZE, fw_addr) ||
2063 CONTAINS(fw_addr, FIRMWARE_SIZE,
Vinay Kalia68398a42012-06-22 18:36:12 -07002064 device->hal_data->
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08002065 device_base_addr) ||
2066 CONTAINS((u32)device->hal_data->
2067 register_base_addr,
2068 reg_size, reg_addr) ||
2069 CONTAINS(reg_addr, reg_size,
2070 (u32)device->hal_data->
2071 register_base_addr) ||
2072 OVERLAPS((u32)device->hal_data->
2073 register_base_addr,
2074 reg_size, reg_addr, reg_size) ||
2075 OVERLAPS(reg_addr, reg_size,
2076 (u32)device->hal_data->
2077 register_base_addr, reg_size) ||
Vinay Kalia68398a42012-06-22 18:36:12 -07002078 OVERLAPS(device->hal_data->
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08002079 device_base_addr,
2080 FIRMWARE_SIZE, fw_addr,
2081 FIRMWARE_SIZE) ||
2082 OVERLAPS(fw_addr, FIRMWARE_SIZE,
Vinay Kalia68398a42012-06-22 18:36:12 -07002083 device->hal_data->
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08002084 device_base_addr,
2085 FIRMWARE_SIZE))) {
2086 return 0;
2087 } else {
Blaine Dietrichf1a7cff2012-07-23 12:14:18 -07002088 dprintk(VIDC_INFO, "Device not registered");
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08002089 return -EINVAL;
2090 }
2091 }
2092 } else {
Blaine Dietrichf1a7cff2012-07-23 12:14:18 -07002093 dprintk(VIDC_INFO, "no device Registered");
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08002094 }
2095 return -EINVAL;
2096}
2097
2098static void vidc_hal_core_work_handler(struct work_struct *work)
2099{
Deva Ramasubramanianc249b752012-05-18 17:31:03 -07002100 struct hal_device *device = list_first_entry(
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08002101 &hal_ctxt.dev_head, struct hal_device, list);
2102
Blaine Dietrichf1a7cff2012-07-23 12:14:18 -07002103 dprintk(VIDC_INFO, " GOT INTERRUPT () ");
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08002104 if (!device->callback) {
Blaine Dietrichf1a7cff2012-07-23 12:14:18 -07002105 dprintk(VIDC_ERR, "No callback function "
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08002106 "to process interrupt: %p\n", device);
2107 return;
2108 }
2109 vidc_hal_core_clear_interrupt(device);
2110 vidc_hal_response_handler(device);
2111 enable_irq(device->hal_data->irq);
2112}
2113static DECLARE_WORK(vidc_hal_work, vidc_hal_core_work_handler);
2114
2115static irqreturn_t vidc_hal_isr(int irq, void *dev)
2116{
2117 struct hal_device *device = dev;
Blaine Dietrichf1a7cff2012-07-23 12:14:18 -07002118 dprintk(VIDC_INFO, "vidc_hal_isr() %d ", irq);
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08002119 disable_irq_nosync(irq);
2120 queue_work(device->vidc_workq, &vidc_hal_work);
Blaine Dietrichf1a7cff2012-07-23 12:14:18 -07002121 dprintk(VIDC_INFO, "vidc_hal_isr() %d ", irq);
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08002122 return IRQ_HANDLED;
2123}
2124
2125void *vidc_hal_add_device(u32 device_id, u32 fw_base_addr, u32 reg_base,
2126 u32 reg_size, u32 irq,
2127 void (*callback) (enum command_response cmd, void *data))
2128{
2129 struct hal_device *hdevice = NULL;
2130 struct hal_data *hal = NULL;
2131 int rc = 0;
2132
Vinay Kalia68398a42012-06-22 18:36:12 -07002133 if (device_id || !reg_base || !reg_size ||
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08002134 !irq || !callback) {
Blaine Dietrichf1a7cff2012-07-23 12:14:18 -07002135 dprintk(VIDC_ERR, "Invalid Paramters");
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08002136 return NULL;
2137 } else {
Blaine Dietrichf1a7cff2012-07-23 12:14:18 -07002138 dprintk(VIDC_INFO, "entered , device_id: %d", device_id);
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08002139 }
2140
2141 if (vidc_hal_check_core_registered(hal_ctxt, fw_base_addr,
2142 reg_base, reg_size, irq)) {
Blaine Dietrichf1a7cff2012-07-23 12:14:18 -07002143 dprintk(VIDC_DBG, "HAL_DATA will be assigned now");
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08002144 hal = (struct hal_data *)
2145 kzalloc(sizeof(struct hal_data), GFP_KERNEL);
2146 if (!hal) {
Blaine Dietrichf1a7cff2012-07-23 12:14:18 -07002147 dprintk(VIDC_ERR, "Failed to alloc");
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08002148 return NULL;
2149 }
2150 hal->irq = irq;
Vinay Kalia68398a42012-06-22 18:36:12 -07002151 hal->device_base_addr = fw_base_addr;
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08002152 hal->register_base_addr =
2153 ioremap_nocache(reg_base, reg_size);
2154 if (!hal->register_base_addr) {
Blaine Dietrichf1a7cff2012-07-23 12:14:18 -07002155 dprintk(VIDC_ERR,
2156 "could not map reg addr %d of size %d",
2157 reg_base, reg_size);
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08002158 goto err_map;
2159 }
2160 INIT_LIST_HEAD(&hal_ctxt.dev_head);
2161 } else {
Blaine Dietrichf1a7cff2012-07-23 12:14:18 -07002162 dprintk(VIDC_ERR, "Core present/Already added");
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08002163 return NULL;
2164 }
2165
2166 hdevice = (struct hal_device *)
2167 kzalloc(sizeof(struct hal_device), GFP_KERNEL);
2168 if (!hdevice) {
Blaine Dietrichf1a7cff2012-07-23 12:14:18 -07002169 dprintk(VIDC_ERR, "failed to allocate new device");
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08002170 goto err_map;
2171 }
2172
2173 INIT_LIST_HEAD(&hdevice->list);
2174 list_add_tail(&hdevice->list, &hal_ctxt.dev_head);
2175 hal_ctxt.dev_count++;
2176 hdevice->device_id = device_id;
2177 hdevice->hal_data = hal;
2178 hdevice->callback = callback;
2179
2180 hdevice->vidc_workq = create_singlethread_workqueue(
2181 "msm_vidc_workerq");
2182 if (!hdevice->vidc_workq) {
Blaine Dietrichf1a7cff2012-07-23 12:14:18 -07002183 dprintk(VIDC_ERR, ": create workq failed\n");
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08002184 goto error_createq;
2185 }
2186
2187 rc = request_irq(irq, vidc_hal_isr, IRQF_TRIGGER_HIGH,
2188 "msm_vidc", hdevice);
2189 if (unlikely(rc)) {
Blaine Dietrichf1a7cff2012-07-23 12:14:18 -07002190 dprintk(VIDC_ERR, "() :request_irq failed\n");
Ashray Kulkarni6ab782b2012-01-26 16:58:01 -08002191 goto error_irq_fail;
2192 }
2193 disable_irq_nosync(irq);
2194 return (void *) hdevice;
2195error_irq_fail:
2196 destroy_workqueue(hdevice->vidc_workq);
2197error_createq:
2198 hal_ctxt.dev_count--;
2199 list_del(&hal_ctxt.dev_head);
2200err_map:
2201 kfree(hal);
2202 return NULL;
2203}
2204
2205void vidc_hal_delete_device(void *device)
2206{
2207 struct hal_device *close, *dev;
2208
2209 if (device) {
2210 dev = (struct hal_device *) device;
2211 list_for_each_entry(close, &hal_ctxt.dev_head, list) {
2212 if (close->hal_data->irq == dev->hal_data->irq) {
2213 hal_ctxt.dev_count--;
2214 free_irq(dev->hal_data->irq, NULL);
2215 list_del(&close->list);
2216 destroy_workqueue(close->vidc_workq);
2217 kfree(close->hal_data);
2218 kfree(close);
2219 break;
2220 }
2221 }
2222
2223 }
2224}