Skip to content

Commit

Permalink
ipu6: ipu-isys-video video node support for camera subdev
Browse files Browse the repository at this point in the history
        - ipu-isys-video.c:
            - control for enhanced node support by pipeline subdevices enumerating
            - inheritance of sub-device controls within same vc
            - s/g_parm ioctl ops to set/get fps on subdev
            - vidioc_enum_framesizes - implement remote sensor polling
            - vidioc_enum_frameintervals - implement remote sensor polling
            - vidioc_enum_fmt - select only sub-device formats
            - vidioc_s_fmt_vid_cap_mplane - set remote link format
            - vidioc_try_fmt_vid_cap_mplane - try remote format
            - link validation for isys entities intel#134
            - metadata support for D4XX_META format

	- ipu-isys-csi2-be-soc.c: link validation intel#134
	    - CSI2 BE SOC has multiple formats on capture pads that's the point
	      where it match external pad0 format which will inherit format
              from CSI-2 external entity.
	- ipu-isys-csi2.c: link validation intel#134
	    - inherit format from CSI-2 external entity.
        - ipu-isys.h: V4L2_CID_IPU_ENUMERATE_LINK
        - ipu-isys-video.h: ipu_isys_video.enum_link_state state for link enumeration by vc
	- ipu-psys.c: fix compilation issue on kernel 5.15
	    - Resloves ipu-psys: MODULE_IMPORT_NS(DMA_BUF) for kernel 5.15 intel#77
	- ipu-isys-queue.c:
	    - Move firmware bring-up from video open to queue start streaming.
	      This will increase firmware stability for start-stop toggling
              without closing video node for all streams.
	    - Move firmware shutdown from video close to queue stop streaming
	      Improves recovery process for multithread processes
              that not close video handle.

Signed-off-by: Dmitry Perchanov <[email protected]>
  • Loading branch information
dmipx committed May 21, 2023
1 parent 38eacec commit 0d0ee57
Show file tree
Hide file tree
Showing 7 changed files with 809 additions and 148 deletions.
31 changes: 31 additions & 0 deletions drivers/media/pci/intel/ipu-isys-csi2-be-soc.c
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,38 @@ static struct v4l2_subdev_ops csi2_be_soc_sd_ops = {
.pad = &csi2_be_soc_sd_pad_ops,
};

static int csi2_be_soc_link_validate(struct media_link *link)
{
struct media_pipeline *media_pipe;
struct ipu_isys_pipeline *ip;
struct v4l2_subdev *source_sd;
struct v4l2_subdev *sink_sd;
struct v4l2_subdev_format fmt = { 0 };

int rval;

if (!link->sink->entity || !link->source->entity)
return -EINVAL;
media_pipe = media_entity_pipeline(link->sink->entity);
if (!media_pipe)
return -EINVAL;

ip = to_ipu_isys_pipeline(media_pipe);
source_sd = media_entity_to_v4l2_subdev(link->source->entity);
sink_sd = media_entity_to_v4l2_subdev(link->sink->entity);

fmt.which = V4L2_SUBDEV_FORMAT_ACTIVE;

fmt.pad = CSI2_PAD_SOURCE;
rval = v4l2_subdev_call(source_sd, pad, get_fmt, NULL, &fmt);

fmt.pad = CSI2_BE_SOC_PAD_SINK;
rval = v4l2_subdev_call(sink_sd, pad, set_fmt, NULL, &fmt);
return v4l2_subdev_link_validate(link);
}

static struct media_entity_operations csi2_be_soc_entity_ops = {
.link_validate = csi2_be_soc_link_validate,
};

static void csi2_be_soc_set_ffmt(struct v4l2_subdev *sd,
Expand Down
13 changes: 13 additions & 0 deletions drivers/media/pci/intel/ipu-isys-csi2.c
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,7 @@ static int csi2_link_validate(struct media_link *link)
struct ipu_isys_pipeline *ip;
struct v4l2_subdev *source_sd;
struct v4l2_subdev *sink_sd;
struct v4l2_subdev_format fmt = { 0 };

int rval;

Expand All @@ -350,8 +351,20 @@ static int csi2_link_validate(struct media_link *link)
ipu_isys_video_add_capture_done(ip, csi2_capture_done);
source_sd = media_entity_to_v4l2_subdev(link->source->entity);
sink_sd = media_entity_to_v4l2_subdev(link->sink->entity);

if (!source_sd)
return -ENODEV;
/* source is external entity, get it's format */
fmt.which = V4L2_SUBDEV_FORMAT_ACTIVE;
fmt.pad = CSI2_PAD_SINK;
rval = v4l2_subdev_call(source_sd, pad, get_fmt, NULL, &fmt);

/* set csi2 format for the same as external entity */
rval = v4l2_subdev_call(sink_sd, pad, set_fmt, NULL, &fmt);

rval = v4l2_subdev_link_validate(link);
if (rval)
return rval;

if (strncmp(source_sd->name, IPU_ISYS_ENTITY_PREFIX,
strlen(IPU_ISYS_ENTITY_PREFIX)) != 0) {
Expand Down
149 changes: 145 additions & 4 deletions drivers/media/pci/intel/ipu-isys-queue.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <linux/module.h>
#include <linux/string.h>
#include <linux/delay.h>
#include <linux/pm_runtime.h>

#include <media/media-entity.h>
#include <media/videobuf2-dma-contig.h>
Expand Down Expand Up @@ -817,6 +818,15 @@ static int __start_streaming(struct vb2_queue *q, unsigned int count)

mutex_unlock(&av->isys->stream_mutex);

if (av->pfmt->css_pixelformat){
rval = aq->link_fmt_validate(aq);
if (rval) {
dev_err(&av->isys->adev->dev,
"%s: link format validation failed (%d)\n",
av->vdev.name, rval);
goto out_unprepare_streaming;
}
}
ip = to_ipu_isys_pipeline(media_entity_pipeline(&av->vdev.entity));
pipe_av = container_of(ip, struct ipu_isys_video, ip);
if (pipe_av != av) {
Expand Down Expand Up @@ -872,6 +882,7 @@ static int __start_streaming(struct vb2_queue *q, unsigned int count)
mutex_lock(&av->mutex);
}

out_unprepare_streaming:
mutex_lock(&av->isys->stream_mutex);
if (first)
ipu_isys_video_prepare_streaming(av, 0);
Expand All @@ -883,12 +894,138 @@ static int __start_streaming(struct vb2_queue *q, unsigned int count)
return rval;
}

static int isys_fw_open(struct ipu_isys_video *av)
{
struct ipu_isys *isys = av->isys;
struct ipu_bus_device *adev = to_ipu_bus_device(&isys->adev->dev);
struct ipu_device *isp = adev->isp;
int rval;
const struct ipu_isys_internal_pdata *ipdata;

dev_warn(&isys->adev->dev, "%s:%d %s: enter\n",
__func__, __LINE__, av->vdev.name);

mutex_lock(&isys->mutex);

if (isys->reset_needed || isp->flr_done) {
mutex_unlock(&isys->mutex);
dev_warn(&isys->adev->dev, "%s:%d %s: isys power cycle required\n",
__func__, __LINE__, av->vdev.name);
return -EIO;
}
mutex_unlock(&isys->mutex);

rval = pm_runtime_get_sync(&isys->adev->dev);
if (rval < 0) {
pm_runtime_put_noidle(&isys->adev->dev);
return rval;
}

mutex_lock(&isys->mutex);
if (isys->video_opened++) {
/* Already open */
mutex_unlock(&isys->mutex);
dev_warn(&isys->adev->dev, "%s:%d %s: Already open, exit %d\n",
__func__, __LINE__, av->vdev.name, isys->video_opened);
return 0;
}

ipdata = isys->pdata->ipdata;
ipu_configure_spc(adev->isp,
&ipdata->hw_variant,
IPU_CPD_PKG_DIR_ISYS_SERVER_IDX,
isys->pdata->base, isys->pkg_dir,
isys->pkg_dir_dma_addr);

/*
* Buffers could have been left to wrong queue at last closure.
* Move them now back to empty buffer queue.
*/
ipu_cleanup_fw_msg_bufs(isys);

if (isys->fwcom) {
/*
* Something went wrong in previous shutdown. As we are now
* restarting isys we can safely delete old context.
*/
dev_err(&isys->adev->dev, "%s:%d %s Clearing old context\n",
__func__, __LINE__, av->vdev.name);
ipu_fw_isys_cleanup(isys);
}

rval = ipu_fw_isys_init(av->isys, ipdata->num_parallel_streams);
if (rval < 0)
goto out_lib_init;

mutex_unlock(&isys->mutex);

dev_warn(&isys->adev->dev, "%s:%d %s: exit\n",
__func__, __LINE__, av->vdev.name);
return 0;

out_lib_init:
isys->video_opened--;
mutex_unlock(&isys->mutex);
pm_runtime_put(&isys->adev->dev);

return rval;
}

static int isys_fw_release(struct ipu_isys_video *av)
{
struct ipu_isys *isys = av->isys;
int ret = 0;

dev_warn(&isys->adev->dev, "%s:%d %s: enter\n",
__func__, __LINE__, av->vdev.name);
mutex_lock(&isys->reset_mutex);
while (isys->in_reset) {
mutex_unlock(&isys->reset_mutex);
dev_warn(&isys->adev->dev, "%s:%d %s: wait for reset\n",
__func__, __LINE__, av->vdev.name);
usleep_range(10000, 11000);
mutex_lock(&isys->reset_mutex);
}
mutex_unlock(&isys->reset_mutex);

mutex_lock(&isys->mutex);
dev_warn(&isys->adev->dev, "%s:%d %s: close fw video_opened: %d\n",
__func__, __LINE__, av->vdev.name, isys->video_opened);
if (isys->video_opened)
isys->video_opened--;
if (!isys->video_opened) {
dev_warn(&isys->adev->dev, "%s:%d %s: close fw\n",
__func__, __LINE__, av->vdev.name);
ipu_fw_isys_close(isys);

if (isys->fwcom) {
isys->reset_needed = true;
ret = -EIO;
}
}

mutex_unlock(&isys->mutex);

if (isys->reset_needed)
pm_runtime_put_sync(&isys->adev->dev);
else
pm_runtime_put(&isys->adev->dev);

dev_warn(&isys->adev->dev, "%s:%d %s: exit\n",
__func__, __LINE__, av->vdev.name);
return ret;
}

static int start_streaming(struct vb2_queue *q, unsigned int count)
{
struct ipu_isys_queue *aq = vb2_queue_to_ipu_isys_queue(q);
struct ipu_isys_video *av = ipu_isys_queue_to_video(aq);
int rval;

rval = isys_fw_open(av);
if (rval < 0) {
dev_err(&av->isys->adev->dev, "isys_fw_open failed: %d\n", rval);
}
mutex_unlock(&av->mutex);
mutex_lock(&av->isys->reset_mutex);
while (av->isys->in_stop_streaming) {
Expand All @@ -903,7 +1040,8 @@ static int start_streaming(struct vb2_queue *q, unsigned int count)
mutex_lock(&av->mutex);

rval = __start_streaming(q, count);

if (rval)
isys_fw_release(av);
return rval;
}

Expand All @@ -912,7 +1050,8 @@ static void reset_stop_streaming(struct ipu_isys_video *av)
struct ipu_isys_pipeline *ip = &av->ip;
struct ipu_isys_queue *aq = &av->aq;

dev_dbg(&av->isys->adev->dev, "%s: stop streaming\n", av->vdev.name);
dev_warn(&av->isys->adev->dev, "%s():%d %s: stop streaming\n",
__func__, __LINE__, av->vdev.name);

mutex_lock(&av->isys->stream_mutex);
if (ip->nr_streaming == ip->nr_queues && ip->streaming)
Expand All @@ -932,7 +1071,8 @@ static int reset_start_streaming(struct ipu_isys_video *av)
unsigned long flags;
int rval;

dev_dbg(&av->isys->adev->dev, "%s: start streaming\n", av->vdev.name);
dev_warn(&av->isys->adev->dev, "%s():%d %s: start streaming\n",
__func__, __LINE__, av->vdev.name);

spin_lock_irqsave(&aq->lock, flags);
while (!list_empty(&aq->active)) {
Expand Down Expand Up @@ -1171,7 +1311,8 @@ static void stop_streaming(struct vb2_queue *q)
mutex_lock(&av->isys->reset_mutex);
av->isys->in_stop_streaming = false;
mutex_unlock(&av->isys->reset_mutex);

if (0 == ip->nr_streaming)
isys_fw_release(av);
}

static unsigned int
Expand Down
Loading

0 comments on commit 0d0ee57

Please sign in to comment.