msm: vidc: Add msm_vidc_wait as a poll interface for kernel clients
Add a new interface msm_vidc_wait that is similar to msm_vidc_poll in
functionality, except intended for kernel-space clients.
Change-Id: Ia08f228f9865dcb8c92ba8fc04692e4b0184daea
Signed-off-by: Deva Ramasubramanian <dramasub@codeaurora.org>
diff --git a/drivers/media/video/msm_vidc/msm_vidc.c b/drivers/media/video/msm_vidc/msm_vidc.c
index c7269d3..ec9dac8 100644
--- a/drivers/media/video/msm_vidc/msm_vidc.c
+++ b/drivers/media/video/msm_vidc/msm_vidc.c
@@ -11,6 +11,7 @@
*
*/
+#include <linux/sched.h>
#include <linux/slab.h>
#include <media/msm_vidc.h>
#include "msm_vidc_internal.h"
@@ -23,21 +24,19 @@
#define MAX_EVENTS 30
-int msm_vidc_poll(void *instance, struct file *filp,
- struct poll_table_struct *wait)
+static int get_poll_flags(void *instance)
{
- int rc = 0;
struct msm_vidc_inst *inst = instance;
struct vb2_queue *outq = &inst->vb2_bufq[OUTPUT_PORT];
struct vb2_queue *capq = &inst->vb2_bufq[CAPTURE_PORT];
struct vb2_buffer *out_vb = NULL;
struct vb2_buffer *cap_vb = NULL;
unsigned long flags;
- poll_wait(filp, &inst->event_handler.wait, wait);
- poll_wait(filp, &capq->done_wq, wait);
- poll_wait(filp, &outq->done_wq, wait);
+ int rc = 0;
+
if (v4l2_event_pending(&inst->event_handler))
rc |= POLLPRI;
+
spin_lock_irqsave(&capq->done_lock, flags);
if (!list_empty(&capq->done_list))
cap_vb = list_first_entry(&capq->done_list, struct vb2_buffer,
@@ -46,6 +45,7 @@
|| cap_vb->state == VB2_BUF_STATE_ERROR))
rc |= POLLIN | POLLRDNORM;
spin_unlock_irqrestore(&capq->done_lock, flags);
+
spin_lock_irqsave(&outq->done_lock, flags);
if (!list_empty(&outq->done_list))
out_vb = list_first_entry(&outq->done_list, struct vb2_buffer,
@@ -54,6 +54,30 @@
|| out_vb->state == VB2_BUF_STATE_ERROR))
rc |= POLLOUT | POLLWRNORM;
spin_unlock_irqrestore(&outq->done_lock, flags);
+
+ return rc;
+}
+
+int msm_vidc_poll(void *instance, struct file *filp,
+ struct poll_table_struct *wait)
+{
+ struct msm_vidc_inst *inst = instance;
+ struct vb2_queue *outq = &inst->vb2_bufq[OUTPUT_PORT];
+ struct vb2_queue *capq = &inst->vb2_bufq[CAPTURE_PORT];
+
+ poll_wait(filp, &inst->event_handler.wait, wait);
+ poll_wait(filp, &capq->done_wq, wait);
+ poll_wait(filp, &outq->done_wq, wait);
+ return get_poll_flags(inst);
+}
+
+/* Kernel client alternative for msm_vidc_poll */
+int msm_vidc_wait(void *instance)
+{
+ struct msm_vidc_inst *inst = instance;
+ int rc = 0;
+
+ wait_event(inst->kernel_event_queue, (rc = get_poll_flags(inst)));
return rc;
}
@@ -385,8 +409,10 @@
INIT_LIST_HEAD(&inst->pendingq);
INIT_LIST_HEAD(&inst->internalbufs);
INIT_LIST_HEAD(&inst->persistbufs);
+ init_waitqueue_head(&inst->kernel_event_queue);
inst->state = MSM_VIDC_CORE_UNINIT_DONE;
inst->core = core;
+
for (i = SESSION_MSG_INDEX(SESSION_MSG_START);
i <= SESSION_MSG_INDEX(SESSION_MSG_END); i++) {
init_completion(&inst->completions[i]);
diff --git a/drivers/media/video/msm_vidc/msm_vidc_common.c b/drivers/media/video/msm_vidc/msm_vidc_common.c
index 563d485..f563416 100644
--- a/drivers/media/video/msm_vidc/msm_vidc_common.c
+++ b/drivers/media/video/msm_vidc/msm_vidc_common.c
@@ -406,6 +406,7 @@
inst->reconfig_width = event_notify->width;
inst->in_reconfig = true;
v4l2_event_queue_fh(&inst->event_handler, &dqevent);
+ wake_up(&inst->kernel_event_queue);
return;
} else {
dprintk(VIDC_ERR,
@@ -499,6 +500,7 @@
dqevent.type = V4L2_EVENT_MSM_VIDC_FLUSH_DONE;
dqevent.id = 0;
v4l2_event_queue_fh(&inst->event_handler, &dqevent);
+ wake_up(&inst->kernel_event_queue);
} else {
dprintk(VIDC_ERR, "Failed to get valid response for flush\n");
}
@@ -516,6 +518,7 @@
dqevent.type = V4L2_EVENT_MSM_VIDC_CLOSE_DONE;
dqevent.id = 0;
v4l2_event_queue_fh(&inst->event_handler, &dqevent);
+ wake_up(&inst->kernel_event_queue);
} else {
dprintk(VIDC_ERR,
"Failed to get valid response for session close\n");
@@ -550,13 +553,17 @@
{
struct msm_vidc_cb_data_done *response = data;
struct vb2_buffer *vb;
+ struct msm_vidc_inst *inst;
if (!response) {
dprintk(VIDC_ERR, "Invalid response from vidc_hal\n");
return;
}
vb = response->clnt_data;
- if (vb)
+ inst = (struct msm_vidc_inst *)response->session_id;
+ if (vb) {
vb2_buffer_done(vb, VB2_BUF_STATE_DONE);
+ wake_up(&inst->kernel_event_queue);
+ }
}
static void handle_fbd(enum command_response cmd, void *data)
@@ -620,6 +627,7 @@
vb->v4l2_planes[0].bytesused,
vb->v4l2_buf.flags);
vb2_buffer_done(vb, VB2_BUF_STATE_DONE);
+ wake_up(&inst->kernel_event_queue);
} else {
/*
* FIXME:
diff --git a/drivers/media/video/msm_vidc/msm_vidc_internal.h b/drivers/media/video/msm_vidc/msm_vidc_internal.h
index 3c14123..1f2eff8 100644
--- a/drivers/media/video/msm_vidc/msm_vidc_internal.h
+++ b/drivers/media/video/msm_vidc/msm_vidc_internal.h
@@ -19,6 +19,7 @@
#include <linux/types.h>
#include <linux/completion.h>
#include <linux/clk.h>
+#include <linux/wait.h>
#include <mach/msm_bus.h>
#include <mach/msm_bus_board.h>
#include <mach/ocmem.h>
@@ -226,6 +227,7 @@
struct completion completions[SESSION_MSG_END - SESSION_MSG_START + 1];
struct v4l2_fh event_handler;
struct msm_smem *extradata_handle;
+ wait_queue_head_t kernel_event_queue;
bool in_reconfig;
u32 reconfig_width;
u32 reconfig_height;
diff --git a/include/media/msm_vidc.h b/include/media/msm_vidc.h
index cfca799..34464c6 100644
--- a/include/media/msm_vidc.h
+++ b/include/media/msm_vidc.h
@@ -68,4 +68,5 @@
int msm_vidc_unsubscribe_event(void *instance,
struct v4l2_event_subscription *sub);
int msm_vidc_dqevent(void *instance, struct v4l2_event *event);
+int msm_vidc_wait(void *instance);
#endif