Skip to content

Commit

Permalink
media: atomisp: Convert to videobuf2 WIP
Browse files Browse the repository at this point in the history
Convert atomisp to use videobuf2.

Note this is still very much a WIP, it compiles but other then that is
completely untested so far!

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
  • Loading branch information
jwrdegoede committed Oct 9, 2022
1 parent 69fc466 commit 5a90e76
Show file tree
Hide file tree
Showing 11 changed files with 300 additions and 769 deletions.
118 changes: 45 additions & 73 deletions drivers/staging/media/atomisp/pci/atomisp_cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
#include <asm/iosf_mbi.h>

#include <media/v4l2-event.h>
#include <media/videobuf-vmalloc.h>

#define CREATE_TRACE_POINTS
#include "atomisp_trace_event.h"
Expand Down Expand Up @@ -662,23 +661,6 @@ void dump_sp_dmem(struct atomisp_device *isp, unsigned int addr,
} while (--size32);
}

static struct videobuf_buffer *atomisp_css_frame_to_vbuf(
struct atomisp_video_pipe *pipe, struct ia_css_frame *frame)
{
struct videobuf_vmalloc_memory *vm_mem;
struct ia_css_frame *handle;
int i;

for (i = 0; pipe->capq.bufs[i]; i++) {
vm_mem = pipe->capq.bufs[i]->priv;
handle = vm_mem->vaddr;
if (handle && handle->data == frame->data)
return pipe->capq.bufs[i];
}

return NULL;
}

int atomisp_buffers_in_css(struct atomisp_video_pipe *pipe)
{
unsigned long irqflags;
Expand All @@ -695,36 +677,37 @@ int atomisp_buffers_in_css(struct atomisp_video_pipe *pipe)
return buffers_in_css;
}

void atomisp_buffer_done(struct atomisp_video_pipe *pipe, struct videobuf_buffer *vb,
int state)
void atomisp_buffer_done(struct ia_css_frame *frame, enum vb2_buffer_state state)
{
struct atomisp_video_pipe *pipe = vb_to_pipe(&frame->vb.vb2_buf);

lockdep_assert_held(&pipe->irq_lock);

vb->ts = ktime_get_ns();
vb->field_count = atomic_read(&pipe->asd->sequence) << 1;
vb->state = state;
list_del(&vb->queue);
wake_up(&vb->done);
frame->vb.vb2_buf.timestamp = ktime_get_ns();
frame->vb.field = pipe->pix.field;
frame->vb.sequence = atomic_read(&pipe->asd->sequence);
list_del(&frame->queue);
vb2_buffer_done(&frame->vb.vb2_buf, state);
}

void atomisp_flush_video_pipe(struct atomisp_video_pipe *pipe, bool warn_on_css_frames)
{
struct videobuf_buffer *_vb, *vb;
struct ia_css_frame *frame, *_frame;
unsigned long irqflags;

spin_lock_irqsave(&pipe->irq_lock, irqflags);

list_for_each_entry_safe(vb, _vb, &pipe->buffers_in_css, queue) {
list_for_each_entry_safe(frame, _frame, &pipe->buffers_in_css, queue) {
WARN_ON_ONCE(warn_on_css_frames);
atomisp_buffer_done(pipe, vb, VIDEOBUF_ERROR);
atomisp_buffer_done(frame, VB2_BUF_STATE_ERROR);
}

list_for_each_entry_safe(vb, _vb, &pipe->activeq, queue)
atomisp_buffer_done(pipe, vb, VIDEOBUF_ERROR);
list_for_each_entry_safe(frame, _frame, &pipe->activeq, queue)
atomisp_buffer_done(frame, VB2_BUF_STATE_ERROR);

list_for_each_entry_safe(vb, _vb, &pipe->buffers_waiting_for_param, queue) {
pipe->frame_request_config_id[vb->i] = 0;
atomisp_buffer_done(pipe, vb, VIDEOBUF_ERROR);
list_for_each_entry_safe(frame, _frame, &pipe->buffers_waiting_for_param, queue) {
pipe->frame_request_config_id[frame->vb.vb2_buf.index] = 0;
atomisp_buffer_done(frame, VB2_BUF_STATE_ERROR);
}

spin_unlock_irqrestore(&pipe->irq_lock, irqflags);
Expand Down Expand Up @@ -873,7 +856,6 @@ void atomisp_buf_done(struct atomisp_sub_device *asd, int error,
enum ia_css_pipe_id css_pipe_id,
bool q_buffers, enum atomisp_input_stream_id stream_id)
{
struct videobuf_buffer *vb = NULL;
struct atomisp_video_pipe *pipe = NULL;
struct atomisp_css_buffer buffer;
bool requeue = false;
Expand Down Expand Up @@ -1026,10 +1008,7 @@ void atomisp_buf_done(struct atomisp_sub_device *asd, int error,
dev_dbg(isp->dev, "%s thumb no flash in this frame\n",
__func__);
}
vb = atomisp_css_frame_to_vbuf(pipe, frame);
WARN_ON(!vb);
if (vb)
pipe->frame_config_id[vb->i] = frame->isp_config_id;
pipe->frame_config_id[frame->vb.vb2_buf.index] = frame->isp_config_id;
if (css_pipe_id == IA_CSS_PIPE_ID_CAPTURE &&
asd->pending_capture_request > 0) {
err = atomisp_css_offline_capture_configure(asd,
Expand Down Expand Up @@ -1065,13 +1044,8 @@ void atomisp_buf_done(struct atomisp_sub_device *asd, int error,

dev_dbg(isp->dev, "%s: main frame with exp_id %d is ready\n",
__func__, frame->exp_id);
vb = atomisp_css_frame_to_vbuf(pipe, frame);
if (!vb) {
WARN_ON(1);
break;
}

i = vb->i;
i = frame->vb.vb2_buf.index;

/* free the parameters */
if (pipe->frame_params[i]) {
Expand Down Expand Up @@ -1182,9 +1156,9 @@ void atomisp_buf_done(struct atomisp_sub_device *asd, int error,
default:
break;
}
if (vb) {
if (frame) {
spin_lock_irqsave(&pipe->irq_lock, irqflags);
atomisp_buffer_done(pipe, vb, error ? VIDEOBUF_ERROR : VIDEOBUF_DONE);
atomisp_buffer_done(frame, error ? VB2_BUF_STATE_ERROR : VB2_BUF_STATE_DONE);
spin_unlock_irqrestore(&pipe->irq_lock, irqflags);
}

Expand Down Expand Up @@ -3655,6 +3629,18 @@ void atomisp_free_css_parameters(struct atomisp_css_params *css_param)
}
}

static void atomisp_move_frame_to_activeq(struct ia_css_frame *frame,
struct atomisp_css_params_with_list *param)
{
struct atomisp_video_pipe *pipe = vb_to_pipe(&frame->vb.vb2_buf);
unsigned long irqflags;

pipe->frame_params[frame->vb.vb2_buf.index] = param;
spin_lock_irqsave(&pipe->irq_lock, irqflags);
list_move_tail(&frame->queue, &pipe->activeq);
spin_unlock_irqrestore(&pipe->irq_lock, irqflags);
}

/*
* Check parameter queue list and buffer queue list to find out if matched items
* and then set parameter to CSS and enqueue buffer to CSS.
Expand All @@ -3665,11 +3651,10 @@ void atomisp_free_css_parameters(struct atomisp_css_params *css_param)
void atomisp_handle_parameter_and_buffer(struct atomisp_video_pipe *pipe)
{
struct atomisp_sub_device *asd = pipe->asd;
struct videobuf_buffer *vb = NULL, *vb_tmp;
struct ia_css_frame *frame = NULL, *frame_tmp;
struct atomisp_css_params_with_list *param = NULL, *param_tmp;
struct videobuf_vmalloc_memory *vm_mem = NULL;
unsigned long irqflags;
bool need_to_enqueue_buffer = false;
int i;

lockdep_assert_held(&asd->isp->mutex);

Expand All @@ -3693,44 +3678,33 @@ void atomisp_handle_parameter_and_buffer(struct atomisp_video_pipe *pipe)
list_empty(&pipe->buffers_waiting_for_param))
return;

list_for_each_entry_safe(vb, vb_tmp,
list_for_each_entry_safe(frame, frame_tmp,
&pipe->buffers_waiting_for_param, queue) {
if (pipe->frame_request_config_id[vb->i]) {
i = frame->vb.vb2_buf.index;
if (pipe->frame_request_config_id[i]) {
list_for_each_entry_safe(param, param_tmp,
&pipe->per_frame_params, list) {
if (pipe->frame_request_config_id[vb->i] !=
param->params.isp_config_id)
if (pipe->frame_request_config_id[i] != param->params.isp_config_id)
continue;

list_del(&param->list);
list_del(&vb->queue);

/*
* clear the request config id as the buffer
* will be handled and enqueued into CSS soon
*/
pipe->frame_request_config_id[vb->i] = 0;
pipe->frame_params[vb->i] = param;
vm_mem = vb->priv;
BUG_ON(!vm_mem);
pipe->frame_request_config_id[i] = 0;
atomisp_move_frame_to_activeq(frame, param);
need_to_enqueue_buffer = true;
break;
}

if (vm_mem) {
spin_lock_irqsave(&pipe->irq_lock, irqflags);
list_add_tail(&vb->queue, &pipe->activeq);
spin_unlock_irqrestore(&pipe->irq_lock, irqflags);
vm_mem = NULL;
need_to_enqueue_buffer = true;
} else {
/* The is the end, stop further loop */
if (list_entry_is_head(param, &pipe->per_frame_params, list)) {
/* The is the end, stop outer loop */
break;
}
} else {
list_del(&vb->queue);
pipe->frame_params[vb->i] = NULL;
spin_lock_irqsave(&pipe->irq_lock, irqflags);
list_add_tail(&vb->queue, &pipe->activeq);
spin_unlock_irqrestore(&pipe->irq_lock, irqflags);
atomisp_move_frame_to_activeq(frame, NULL);
need_to_enqueue_buffer = true;
}
}
Expand Down Expand Up @@ -5537,8 +5511,6 @@ int atomisp_set_fmt(struct file *file, void *unused, struct v4l2_format *f)
f->fmt.pix.priv = PAGE_ALIGN(pipe->pix.width *
pipe->pix.height * 2);

pipe->capq.field = f->fmt.pix.field;

/*
* If in video 480P case, no GFX throttle
*/
Expand Down
3 changes: 1 addition & 2 deletions drivers/staging/media/atomisp/pci/atomisp_cmd.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ struct camera_mipi_info *atomisp_to_sensor_mipi_info(struct v4l2_subdev *sd);
struct atomisp_video_pipe *atomisp_to_video_pipe(struct video_device *dev);
int atomisp_reset(struct atomisp_device *isp);
int atomisp_buffers_in_css(struct atomisp_video_pipe *pipe);
void atomisp_buffer_done(struct atomisp_video_pipe *pipe, struct videobuf_buffer *buf,
int state);
void atomisp_buffer_done(struct ia_css_frame *frame, enum vb2_buffer_state state);
void atomisp_flush_video_pipe(struct atomisp_video_pipe *pipe, bool warn_on_css_frames);
void atomisp_flush_bufs_and_wakeup(struct atomisp_sub_device *asd);
void atomisp_clear_css_buffer_counters(struct atomisp_sub_device *asd);
Expand Down
6 changes: 1 addition & 5 deletions drivers/staging/media/atomisp/pci/atomisp_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

#include <linux/v4l2-mediabus.h>

#include <media/videobuf-core.h>
#include <media/videobuf2-v4l2.h>

#include "atomisp_compat.h"

Expand Down Expand Up @@ -64,8 +64,4 @@ struct atomisp_fmt {
u32 bayer_order;
};

struct atomisp_buffer {
struct videobuf_buffer vb;
};

#endif
3 changes: 1 addition & 2 deletions drivers/staging/media/atomisp/pci/atomisp_compat.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
#include "atomisp_compat_css20.h"

#include "../../include/linux/atomisp.h"
#include <media/videobuf-vmalloc.h>

struct atomisp_device;
struct atomisp_sub_device;
Expand Down Expand Up @@ -61,7 +60,7 @@ int atomisp_css_irq_enable(struct atomisp_device *isp,
enum ia_css_irq_info info, bool enable);

int atomisp_q_video_buffer_to_css(struct atomisp_sub_device *asd,
struct videobuf_vmalloc_memory *vm_mem,
struct ia_css_frame *frame,
enum atomisp_input_stream_id stream_id,
enum ia_css_buffer_type css_buf_type,
enum ia_css_pipe_id css_pipe_id);
Expand Down
4 changes: 2 additions & 2 deletions drivers/staging/media/atomisp/pci/atomisp_compat_css20.c
Original file line number Diff line number Diff line change
Expand Up @@ -996,7 +996,7 @@ void atomisp_css_init_struct(struct atomisp_sub_device *asd)
}

int atomisp_q_video_buffer_to_css(struct atomisp_sub_device *asd,
struct videobuf_vmalloc_memory *vm_mem,
struct ia_css_frame *frame,
enum atomisp_input_stream_id stream_id,
enum ia_css_buffer_type css_buf_type,
enum ia_css_pipe_id css_pipe_id)
Expand All @@ -1006,7 +1006,7 @@ int atomisp_q_video_buffer_to_css(struct atomisp_sub_device *asd,
int err;

css_buf.type = css_buf_type;
css_buf.data.frame = vm_mem->vaddr;
css_buf.data.frame = frame;

err = ia_css_pipe_enqueue_buffer(
stream_env->pipes[css_pipe_id], &css_buf);
Expand Down
Loading

0 comments on commit 5a90e76

Please sign in to comment.