[PATCH v3 2/2] media: ipu3-imgu: Remove dead code for NULL check
Since ipu3_css_buf_dequeue() never returns NULL, remove the dead code to fix static checker warning: drivers/staging/media/ipu3/ipu3.c:493 imgu_isr_threaded() warn: 'b' is an error pointer or valid Reported-by: Dan Carpenter [Bug report: https://lore.kernel.org/linux-media/20190104122856.GA1169@kadam/] Signed-off-by: Yong Zhi Reviewed-by: Tomasz Figa --- drivers/staging/media/ipu3/ipu3.c | 11 +-- 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/drivers/staging/media/ipu3/ipu3.c b/drivers/staging/media/ipu3/ipu3.c index d521b3a..839d939 100644 --- a/drivers/staging/media/ipu3/ipu3.c +++ b/drivers/staging/media/ipu3/ipu3.c @@ -489,12 +489,11 @@ static irqreturn_t imgu_isr_threaded(int irq, void *imgu_ptr) mutex_unlock(&imgu->lock); } while (PTR_ERR(b) == -EAGAIN); - if (IS_ERR_OR_NULL(b)) { - if (!b || PTR_ERR(b) == -EBUSY) /* All done */ - break; - dev_err(&imgu->pci_dev->dev, - "failed to dequeue buffers (%ld)\n", - PTR_ERR(b)); + if (IS_ERR(b)) { + if (PTR_ERR(b) != -EBUSY) /* All done */ + dev_err(&imgu->pci_dev->dev, + "failed to dequeue buffers (%ld)\n", + PTR_ERR(b)); break; } -- 2.7.4
[PATCH v3 1/2] media: ipu3-imgu: Use MENU type for mode control
This addresses the below TODO item. - Use V4L2_CTRL_TYPE_MENU for dual-pipe mode control. (Sakari) Signed-off-by: Yong Zhi Reviewed-by: Tomasz Figa Acked-by: Sakari Ailus --- drivers/staging/media/ipu3/TODO | 2 -- drivers/staging/media/ipu3/include/intel-ipu3.h | 6 -- drivers/staging/media/ipu3/ipu3-v4l2.c | 15 +++ 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/drivers/staging/media/ipu3/TODO b/drivers/staging/media/ipu3/TODO index 905bbb1..0dc9a2e 100644 --- a/drivers/staging/media/ipu3/TODO +++ b/drivers/staging/media/ipu3/TODO @@ -11,8 +11,6 @@ staging directory. - Prefix imgu for all public APIs, i.e. change ipu3_v4l2_register() to imgu_v4l2_register(). (Sakari) -- Use V4L2_CTRL_TYPE_MENU for dual-pipe mode control. (Sakari) - - IPU3 driver documentation (Laurent) Add diagram in driver rst to describe output capability. Comments on configuring v4l2 subdevs for CIO2 and ImgU. diff --git a/drivers/staging/media/ipu3/include/intel-ipu3.h b/drivers/staging/media/ipu3/include/intel-ipu3.h index ec0b748..eb6f52a 100644 --- a/drivers/staging/media/ipu3/include/intel-ipu3.h +++ b/drivers/staging/media/ipu3/include/intel-ipu3.h @@ -16,12 +16,6 @@ #define V4L2_CID_INTEL_IPU3_BASE (V4L2_CID_USER_BASE + 0x10c0) #define V4L2_CID_INTEL_IPU3_MODE (V4L2_CID_INTEL_IPU3_BASE + 1) -/* custom ctrl to set pipe mode */ -enum ipu3_running_mode { - IPU3_RUNNING_MODE_VIDEO = 0, - IPU3_RUNNING_MODE_STILL = 1, -}; - /*** ipu3_uapi_stats_3a ***/ #define IPU3_UAPI_MAX_STRIPES 2 diff --git a/drivers/staging/media/ipu3/ipu3-v4l2.c b/drivers/staging/media/ipu3/ipu3-v4l2.c index c793603..e758a65 100644 --- a/drivers/staging/media/ipu3/ipu3-v4l2.c +++ b/drivers/staging/media/ipu3/ipu3-v4l2.c @@ -12,6 +12,9 @@ / v4l2_subdev_ops / +#define IPU3_RUNNING_MODE_VIDEO0 +#define IPU3_RUNNING_MODE_STILL1 + static int ipu3_subdev_open(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh) { struct imgu_v4l2_subdev *imgu_sd = container_of(sd, @@ -1035,15 +1038,19 @@ static const struct v4l2_ctrl_ops ipu3_subdev_ctrl_ops = { .s_ctrl = ipu3_sd_s_ctrl, }; +static const char * const ipu3_ctrl_mode_strings[] = { + "Video mode", + "Still mode", +}; + static const struct v4l2_ctrl_config ipu3_subdev_ctrl_mode = { .ops = &ipu3_subdev_ctrl_ops, .id = V4L2_CID_INTEL_IPU3_MODE, .name = "IPU3 Pipe Mode", - .type = V4L2_CTRL_TYPE_INTEGER, - .min = IPU3_RUNNING_MODE_VIDEO, - .max = IPU3_RUNNING_MODE_STILL, - .step = 1, + .type = V4L2_CTRL_TYPE_MENU, + .max = ARRAY_SIZE(ipu3_ctrl_mode_strings) - 1, .def = IPU3_RUNNING_MODE_VIDEO, + .qmenu = ipu3_ctrl_mode_strings, }; / Framework registration / -- 2.7.4
RE: [PATCH v2 2/2] media: ipu3-imgu: Remove dead code for NULL check
Hi, Sakari, > -Original Message- > From: Sakari Ailus [mailto:sakari.ai...@linux.intel.com] > Sent: Friday, February 1, 2019 2:43 AM > To: Zhi, Yong > Cc: linux-media@vger.kernel.org; Mani, Rajmohan > ; tf...@chromium.org; > laurent.pinch...@ideasonboard.com; hans.verk...@cisco.com; > mche...@kernel.org; dan.carpen...@oracle.com; Qiu, Tian Shu > ; Cao, Bingbu > Subject: Re: [PATCH v2 2/2] media: ipu3-imgu: Remove dead code for NULL > check > > Hi Yong, > > On Wed, Jan 16, 2019 at 09:18:47AM -0800, Yong Zhi wrote: > > Since ipu3_css_buf_dequeue() never returns NULL, remove the dead code > > to fix static checker warning: > > > > drivers/staging/media/ipu3/ipu3.c:493 imgu_isr_threaded() > > warn: 'b' is an error pointer or valid > > > > Reported-by: Dan Carpenter [Bug report: > > https://lore.kernel.org/linux-media/20190104122856.GA1169@kadam/] > > Signed-off-by: Yong Zhi > > Reviewed-by: Tomasz Figa > > Reviewed-by: Laurent Pinchart > > I don't see Laurent's Reviewed-by: tag on the list. Did you get that from him > off-list? If he hasn't given one, please send v3 without that tag. > The bug report link was suggested by Laurent, so that I assume he reviewed the patch, I can re-send without the tag if this does not count. > Thanks. > > -- > Sakari Ailus > sakari.ai...@linux.intel.com
[PATCH v3 1/1] media: ipu3: update meta format documentation
Language improvements, fix entity naming, make pipeline a graph and move device usage documentation to device documentation ipu3.rst. Signed-off-by: Yong Zhi --- v3 - Outline main changes in commit message. - Remove the intel-ipu3.h renaming from this patch. v2 Rename stats_4a_config to stats_3a_config in intel-ipu3.h. Documentation/media/uapi/v4l/meta-formats.rst | 2 +- .../media/uapi/v4l/pixfmt-meta-intel-ipu3.rst | 119 ++--- Documentation/media/v4l-drivers/ipu3.rst | 147 + 3 files changed, 159 insertions(+), 109 deletions(-) diff --git a/Documentation/media/uapi/v4l/meta-formats.rst b/Documentation/media/uapi/v4l/meta-formats.rst index 5f956fa..b10ca9e 100644 --- a/Documentation/media/uapi/v4l/meta-formats.rst +++ b/Documentation/media/uapi/v4l/meta-formats.rst @@ -19,8 +19,8 @@ These formats are used for the :ref:`metadata` interface only. .. toctree:: :maxdepth: 1 -pixfmt-meta-intel-ipu3 pixfmt-meta-d4xx +pixfmt-meta-intel-ipu3 pixfmt-meta-uvc pixfmt-meta-vsp1-hgo pixfmt-meta-vsp1-hgt diff --git a/Documentation/media/uapi/v4l/pixfmt-meta-intel-ipu3.rst b/Documentation/media/uapi/v4l/pixfmt-meta-intel-ipu3.rst index 659e58a..7fb5433 100644 --- a/Documentation/media/uapi/v4l/pixfmt-meta-intel-ipu3.rst +++ b/Documentation/media/uapi/v4l/pixfmt-meta-intel-ipu3.rst @@ -30,21 +30,22 @@ V4L2_META_FMT_IPU3_PARAMS ('ip3p'), V4L2_META_FMT_IPU3_3A ('ip3s') ** -.. c:type:: ipu3_uapi_stats_3a +.. ipu3_uapi_stats_3a 3A statistics = -For IPU3 ImgU, the 3A statistics accelerators collect different statistics over -an input bayer frame. Those statistics, defined in data struct :c:type:`ipu3_uapi_stats_3a`, -are obtained from "ipu3-imgu 3a stat" metadata capture video node, which are then -passed to user space for statistics analysis using :c:type:`v4l2_meta_format` interface. +The IPU3 ImgU 3A statistics accelerators collect different statistics over +an input Bayer frame. Those statistics are obtained from the "ipu3-imgu [01] 3a +stat" metadata capture video nodes, using the :c:type:`v4l2_meta_format` +interface. They are formatted as described by the :c:type:`ipu3_uapi_stats_3a` +structure. The statistics collected are AWB (Auto-white balance) RGBS (Red, Green, Blue and Saturation measure) cells, AWB filter response, AF (Auto-focus) filter response, and AE (Auto-exposure) histogram. -struct :c:type:`ipu3_uapi_4a_config` saves configurable parameters for all above. +The struct :c:type:`ipu3_uapi_4a_config` saves all configurable parameters. .. code-block:: c @@ -60,105 +61,14 @@ struct :c:type:`ipu3_uapi_4a_config` saves configurable parameters for all above struct ipu3_uapi_ff_status stats_3a_status; }; -.. c:type:: ipu3_uapi_params +.. ipu3_uapi_params Pipeline parameters === -IPU3 pipeline has a number of image processing stages, each of which takes a -set of parameters as input. The major stages of pipelines are shown here: - -Raw pixels -> Bayer Downscaling -> Optical Black Correction -> - -Linearization -> Lens Shading Correction -> White Balance / Exposure / - -Focus Apply -> Bayer Noise Reduction -> ANR -> Demosaicing -> Color - -Correction Matrix -> Gamma correction -> Color Space Conversion -> - -Chroma Down Scaling -> Chromatic Noise Reduction -> Total Color - -Correction -> XNR3 -> TNR -> DDR - -The table below presents a description of the above algorithms. - - === -NameDescription - === -Optical Black Correction Optical Black Correction block subtracts a pre-defined -value from the respective pixel values to obtain better -image quality. -Defined in :c:type:`ipu3_uapi_obgrid_param`. -Linearization This algo block uses linearization parameters to -address non-linearity sensor effects. The Lookup table -table is defined in -:c:type:`ipu3_uapi_isp_lin_vmem_params`. -SHD Lens shading correction is used to correct spatial -non-uniformity of the pixel response due to optical -lens shading. This is done by applying a different gain -for each pixel. The gain, black level etc are -configured in :c:type:`ipu3_uapi_shd_config_static`. -BNR Bayer noise reduction block removes image noise by -applying a bilateral filter. -See :c:type:`ipu3_uapi_bnr_static_config
RE: [PATCH v2] media: ipu3: update meta format documentation
Hi, Sakari, > -Original Message- > From: Sakari Ailus [mailto:sakari.ai...@linux.intel.com] > Sent: Wednesday, January 23, 2019 11:25 PM > To: Zhi, Yong > Cc: linux-media@vger.kernel.org; laurent.pinch...@ideasonboard.com; > Mani, Rajmohan ; tf...@chromium.org; > hans.verk...@cisco.com; mche...@kernel.org; Qiu, Tian Shu > ; Cao, Bingbu > Subject: Re: [PATCH v2] media: ipu3: update meta format documentation > > Hi Yong, > > On Wed, Jan 23, 2019 at 11:35:56AM -0800, Yong Zhi wrote: > > Make changes based on Laurent's v8 review: > > https://www.spinics.net/lists/linux-media/msg144408.html > > Could you outline the changes made by this patch, instead of referring to an > e-mail on a list, please? A short summary is sufficient. Such as: > > Language improvements, fix entity naming, make pipeline a graph and move > device usage documentation to device documentation (out of format > documentation). > > I'd put the struch rename in the header into a separate patch: it's not about > documentation. > Sure, Tomasz also suggested few struct name changes, I will put them together in the header patch. > > > > Signed-off-by: Yong Zhi > > --- > > v2 > > > > Rename stats_4a_config to stats_3a_config in intel-ipu3.h. > > > > Documentation/media/uapi/v4l/meta-formats.rst | 2 +- > > .../media/uapi/v4l/pixfmt-meta-intel-ipu3.rst | 119 ++--- > > Documentation/media/v4l-drivers/ipu3.rst | 147 > + > > drivers/staging/media/ipu3/include/intel-ipu3.h| 8 +- > > 4 files changed, 163 insertions(+), 113 deletions(-) > > > > diff --git a/Documentation/media/uapi/v4l/meta-formats.rst > > b/Documentation/media/uapi/v4l/meta-formats.rst > > index 5f956fa..b10ca9e 100644 > > --- a/Documentation/media/uapi/v4l/meta-formats.rst > > +++ b/Documentation/media/uapi/v4l/meta-formats.rst > > @@ -19,8 +19,8 @@ These formats are used for the :ref:`metadata` > interface only. > > .. toctree:: > > :maxdepth: 1 > > > > -pixfmt-meta-intel-ipu3 > > pixfmt-meta-d4xx > > +pixfmt-meta-intel-ipu3 > > pixfmt-meta-uvc > > pixfmt-meta-vsp1-hgo > > pixfmt-meta-vsp1-hgt > > diff --git a/Documentation/media/uapi/v4l/pixfmt-meta-intel-ipu3.rst > > b/Documentation/media/uapi/v4l/pixfmt-meta-intel-ipu3.rst > > index 659e58a..7fb5433 100644 > > --- a/Documentation/media/uapi/v4l/pixfmt-meta-intel-ipu3.rst > > +++ b/Documentation/media/uapi/v4l/pixfmt-meta-intel-ipu3.rst > > @@ -30,21 +30,22 @@ > > V4L2_META_FMT_IPU3_PARAMS ('ip3p'), V4L2_META_FMT_IPU3_3A > ('ip3s') > > > > ** > > > > -.. c:type:: ipu3_uapi_stats_3a > > +.. ipu3_uapi_stats_3a > > > > 3A statistics > > = > > > > -For IPU3 ImgU, the 3A statistics accelerators collect different > > statistics over -an input bayer frame. Those statistics, defined in > > data struct :c:type:`ipu3_uapi_stats_3a`, -are obtained from > > "ipu3-imgu 3a stat" metadata capture video node, which are then -passed > to user space for statistics analysis using :c:type:`v4l2_meta_format` > interface. > > +The IPU3 ImgU 3A statistics accelerators collect different statistics > > +over an input Bayer frame. Those statistics are obtained from the > > +"ipu3-imgu [01] 3a stat" metadata capture video nodes, using the > > +:c:type:`v4l2_meta_format` interface. They are formatted as described > > +by the :c:type:`ipu3_uapi_stats_3a` structure. > > > > The statistics collected are AWB (Auto-white balance) RGBS (Red, > > Green, Blue and Saturation measure) cells, AWB filter response, AF > > (Auto-focus) filter response, and AE (Auto-exposure) histogram. > > > > -struct :c:type:`ipu3_uapi_4a_config` saves configurable parameters for all > above. > > +The struct :c:type:`ipu3_uapi_4a_config` saves all configurable parameters. > > > > .. code-block:: c > > > > @@ -60,105 +61,14 @@ struct :c:type:`ipu3_uapi_4a_config` saves > configurable parameters for all above > > struct ipu3_uapi_ff_status stats_3a_status; > > }; > > > > -.. c:type:: ipu3_uapi_params > > +.. ipu3_uapi_params > > > > Pipeline parameters > > === > > > > -IPU3 pipeline has a number of image processing stages, each of which > > takes a -set of parameters as input. The major stages of pipelines are > shown here: &
RE: [PATCH v8 15/17] media: v4l: Add Intel IPU3 meta buffer formats
Hi, Laurent, > -Original Message- > From: Laurent Pinchart [mailto:laurent.pinch...@ideasonboard.com] > Sent: Tuesday, January 22, 2019 1:22 PM > To: Zhi, Yong > Cc: linux-media@vger.kernel.org; sakari.ai...@linux.intel.com; > tf...@chromium.org; Mani, Rajmohan ; > Toivonen, Tuukka ; Hu, Jerry W > ; Qiu, Tian Shu ; > hans.verk...@cisco.com; mche...@kernel.org; Cao, Bingbu > > Subject: Re: [PATCH v8 15/17] media: v4l: Add Intel IPU3 meta buffer formats > > Hi Yong, > > On Thu, Jan 10, 2019 at 06:35:11PM +, Zhi, Yong wrote: > > On Tuesday, December 11, 2018 6:59 AM, Laurent Pinchart wrote: > > > On Friday, 7 December 2018 03:03:40 EET Yong Zhi wrote: > > >> Add IPU3-specific meta formats for processing parameters and 3A > > >> statistics. > > >> > > >> V4L2_META_FMT_IPU3_PARAMS > > >> V4L2_META_FMT_IPU3_STAT_3A > > >> > > >> Signed-off-by: Yong Zhi > > >> Reviewed-by: Laurent Pinchart > > > > > > My Reviewed-by tag was related to the format part only (v4l2-ioctl.c > > > and > > > videodev2.h) :-) Please see below for more comments about the > > > documentation. > > > > > >> --- > > >> Documentation/media/uapi/v4l/meta-formats.rst | 1 + > > >> .../media/uapi/v4l/pixfmt-meta-intel-ipu3.rst | 178 > ++ > > >> drivers/media/v4l2-core/v4l2-ioctl.c | 2 + > > >> include/uapi/linux/videodev2.h | 4 + > > >> 4 files changed, 185 insertions(+) create mode 100644 > > >> Documentation/media/uapi/v4l/pixfmt-meta-intel-ipu3.rst > > [snip] > > > >> diff --git > > >> a/Documentation/media/uapi/v4l/pixfmt-meta-intel-ipu3.rst > > >> b/Documentation/media/uapi/v4l/pixfmt-meta-intel-ipu3.rst new file > > >> mode > > >> 100644 > > >> index ..8cd30ffbf8b8 > > >> --- /dev/null > > >> +++ b/Documentation/media/uapi/v4l/pixfmt-meta-intel-ipu3.rst > > [snip] > > > >> +struct :c:type:`ipu3_uapi_4a_config` saves configurable parameters > > >> +for all > > >> above. > > > > > > I would write it as "The > > > > > > By the way why "4a" when the documentation talks about 3A ? > > > Shouldn't the structure be called ipu3_uapi_3a_config ? > > > > > > > The 4th "a" refers to the AWB filter response config. > > But the automatic algorithms are still automatic white balance, automatic > exposure and automatic focus, right, with ipu3_uapi_awb_fr_raw_buffer > being part of AWB, right ? > That's right, we still call it ipu3_uapi_stats_3a instead of ipu3_uapi_stats_4a. I have no problem to rename ipu3_uapi_4a_config to ipu3_uapi_3a_config. I can resend the patch with this update if no one opposes, thanks!! > > >> + > > >> +.. code-block:: c > > >> + > > >> +struct ipu3_uapi_stats_3a { > > >> +struct ipu3_uapi_awb_raw_buffer awb_raw_buffer; > > >> +struct ipu3_uapi_ae_raw_buffer_aligned > > >> ae_raw_buffer[IPU3_UAPI_MAX_STRIPES]; > > >> +struct ipu3_uapi_af_raw_buffer > > >> af_raw_buffer; > > >> +struct ipu3_uapi_awb_fr_raw_buffer awb_fr_raw_buffer; > > >> +struct ipu3_uapi_4a_config stats_4a_config; > > >> +__u32 ae_join_buffers; > > >> +__u8 padding[28]; > > >> +struct ipu3_uapi_stats_3a_bubble_info_per_stripe > > >> stats_3a_bubble_per_stripe; > > >> +struct ipu3_uapi_ff_status stats_3a_status; > > >> +}; > > >> > > >> +.. c:type:: ipu3_uapi_params > > [snip] > > -- > Regards, > > Laurent Pinchart
[PATCH v2 2/2] media: ipu3-imgu: Remove dead code for NULL check
Since ipu3_css_buf_dequeue() never returns NULL, remove the dead code to fix static checker warning: drivers/staging/media/ipu3/ipu3.c:493 imgu_isr_threaded() warn: 'b' is an error pointer or valid Reported-by: Dan Carpenter [Bug report: https://lore.kernel.org/linux-media/20190104122856.GA1169@kadam/] Signed-off-by: Yong Zhi Reviewed-by: Tomasz Figa Reviewed-by: Laurent Pinchart --- drivers/staging/media/ipu3/ipu3.c | 11 +-- 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/drivers/staging/media/ipu3/ipu3.c b/drivers/staging/media/ipu3/ipu3.c index d521b3a..839d939 100644 --- a/drivers/staging/media/ipu3/ipu3.c +++ b/drivers/staging/media/ipu3/ipu3.c @@ -489,12 +489,11 @@ static irqreturn_t imgu_isr_threaded(int irq, void *imgu_ptr) mutex_unlock(&imgu->lock); } while (PTR_ERR(b) == -EAGAIN); - if (IS_ERR_OR_NULL(b)) { - if (!b || PTR_ERR(b) == -EBUSY) /* All done */ - break; - dev_err(&imgu->pci_dev->dev, - "failed to dequeue buffers (%ld)\n", - PTR_ERR(b)); + if (IS_ERR(b)) { + if (PTR_ERR(b) != -EBUSY) /* All done */ + dev_err(&imgu->pci_dev->dev, + "failed to dequeue buffers (%ld)\n", + PTR_ERR(b)); break; } -- 2.7.4
[PATCH v2 1/2] media: ipu3-imgu: Use MENU type for mode control
This addresses the below TODO item. - Use V4L2_CTRL_TYPE_MENU for dual-pipe mode control. (Sakari) Signed-off-by: Yong Zhi Reviewed-by: Tomasz Figa Acked-by: Sakari Ailus --- drivers/staging/media/ipu3/TODO | 2 -- drivers/staging/media/ipu3/include/intel-ipu3.h | 6 -- drivers/staging/media/ipu3/ipu3-v4l2.c | 15 +++ 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/drivers/staging/media/ipu3/TODO b/drivers/staging/media/ipu3/TODO index 905bbb1..0dc9a2e 100644 --- a/drivers/staging/media/ipu3/TODO +++ b/drivers/staging/media/ipu3/TODO @@ -11,8 +11,6 @@ staging directory. - Prefix imgu for all public APIs, i.e. change ipu3_v4l2_register() to imgu_v4l2_register(). (Sakari) -- Use V4L2_CTRL_TYPE_MENU for dual-pipe mode control. (Sakari) - - IPU3 driver documentation (Laurent) Add diagram in driver rst to describe output capability. Comments on configuring v4l2 subdevs for CIO2 and ImgU. diff --git a/drivers/staging/media/ipu3/include/intel-ipu3.h b/drivers/staging/media/ipu3/include/intel-ipu3.h index ec0b748..eb6f52a 100644 --- a/drivers/staging/media/ipu3/include/intel-ipu3.h +++ b/drivers/staging/media/ipu3/include/intel-ipu3.h @@ -16,12 +16,6 @@ #define V4L2_CID_INTEL_IPU3_BASE (V4L2_CID_USER_BASE + 0x10c0) #define V4L2_CID_INTEL_IPU3_MODE (V4L2_CID_INTEL_IPU3_BASE + 1) -/* custom ctrl to set pipe mode */ -enum ipu3_running_mode { - IPU3_RUNNING_MODE_VIDEO = 0, - IPU3_RUNNING_MODE_STILL = 1, -}; - /*** ipu3_uapi_stats_3a ***/ #define IPU3_UAPI_MAX_STRIPES 2 diff --git a/drivers/staging/media/ipu3/ipu3-v4l2.c b/drivers/staging/media/ipu3/ipu3-v4l2.c index c793603..e758a65 100644 --- a/drivers/staging/media/ipu3/ipu3-v4l2.c +++ b/drivers/staging/media/ipu3/ipu3-v4l2.c @@ -12,6 +12,9 @@ / v4l2_subdev_ops / +#define IPU3_RUNNING_MODE_VIDEO0 +#define IPU3_RUNNING_MODE_STILL1 + static int ipu3_subdev_open(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh) { struct imgu_v4l2_subdev *imgu_sd = container_of(sd, @@ -1035,15 +1038,19 @@ static const struct v4l2_ctrl_ops ipu3_subdev_ctrl_ops = { .s_ctrl = ipu3_sd_s_ctrl, }; +static const char * const ipu3_ctrl_mode_strings[] = { + "Video mode", + "Still mode", +}; + static const struct v4l2_ctrl_config ipu3_subdev_ctrl_mode = { .ops = &ipu3_subdev_ctrl_ops, .id = V4L2_CID_INTEL_IPU3_MODE, .name = "IPU3 Pipe Mode", - .type = V4L2_CTRL_TYPE_INTEGER, - .min = IPU3_RUNNING_MODE_VIDEO, - .max = IPU3_RUNNING_MODE_STILL, - .step = 1, + .type = V4L2_CTRL_TYPE_MENU, + .max = ARRAY_SIZE(ipu3_ctrl_mode_strings) - 1, .def = IPU3_RUNNING_MODE_VIDEO, + .qmenu = ipu3_ctrl_mode_strings, }; / Framework registration / -- 2.7.4
RE: [PATCH 2/2] media: ipu3-imgu: Remove dead code for NULL check
Hi, Tomasz, > -Original Message- > From: Tomasz Figa [mailto:tf...@chromium.org] > Sent: Monday, January 14, 2019 11:38 PM > To: Zhi, Yong > Cc: Linux Media Mailing List ; Sakari Ailus > ; Mani, Rajmohan > ; Qiu, Tian Shu ; > Laurent Pinchart ; Hans Verkuil > ; Mauro Carvalho Chehab ; > Cao, Bingbu ; dan.carpen...@oracle.com > Subject: Re: [PATCH 2/2] media: ipu3-imgu: Remove dead code for NULL > check > > Hi Yong, > > On Tue, Jan 15, 2019 at 12:38 PM Yong Zhi wrote: > > > > Since ipu3_css_buf_dequeue() never returns NULL, remove the dead code > > to fix static checker warning: > > > > drivers/staging/media/ipu3/ipu3.c:493 imgu_isr_threaded() > > warn: 'b' is an error pointer or valid > > > > Signed-off-by: Yong Zhi > > --- > > Link to Dan's bug report: > > https://www.spinics.net/lists/linux-media/msg145043.html > > You can add Dan's Reported-by above your Signed-off-by to properly credit > him. I'd also add a comment below that Reported-by, e.g. > > [Bug report: https://www.spinics.net/lists/linux-media/msg145043.html] > > so that it doesn't get removed when applying the patch, as it would get now, > because any text right in this area is ignored by git. > > With that fixes, feel free to add my Reviewed-by. Thanks a lot for the detailed instructions :) > > Best regards, > Tomasz > > > > > drivers/staging/media/ipu3/ipu3.c | 11 +-- > > 1 file changed, 5 insertions(+), 6 deletions(-) > > > > diff --git a/drivers/staging/media/ipu3/ipu3.c > > b/drivers/staging/media/ipu3/ipu3.c > > index d521b3afb8b1..839d9398f8e9 100644 > > --- a/drivers/staging/media/ipu3/ipu3.c > > +++ b/drivers/staging/media/ipu3/ipu3.c > > @@ -489,12 +489,11 @@ static irqreturn_t imgu_isr_threaded(int irq, void > *imgu_ptr) > > mutex_unlock(&imgu->lock); > > } while (PTR_ERR(b) == -EAGAIN); > > > > - if (IS_ERR_OR_NULL(b)) { > > - if (!b || PTR_ERR(b) == -EBUSY) /* All done */ > > - break; > > - dev_err(&imgu->pci_dev->dev, > > - "failed to dequeue buffers (%ld)\n", > > - PTR_ERR(b)); > > + if (IS_ERR(b)) { > > + if (PTR_ERR(b) != -EBUSY) /* All done */ > > + dev_err(&imgu->pci_dev->dev, > > + "failed to dequeue buffers (%ld)\n", > > + PTR_ERR(b)); > > break; > > } > > > > -- > > 2.7.4 > >
[PATCH 1/2] media: ipu3-imgu: Use MENU type for mode control
This addresses the below TODO item. - Use V4L2_CTRL_TYPE_MENU for dual-pipe mode control. (Sakari) Signed-off-by: Yong Zhi --- drivers/staging/media/ipu3/TODO | 2 -- drivers/staging/media/ipu3/include/intel-ipu3.h | 6 -- drivers/staging/media/ipu3/ipu3-v4l2.c | 18 +- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/drivers/staging/media/ipu3/TODO b/drivers/staging/media/ipu3/TODO index 905bbb190217..0dc9a2e79978 100644 --- a/drivers/staging/media/ipu3/TODO +++ b/drivers/staging/media/ipu3/TODO @@ -11,8 +11,6 @@ staging directory. - Prefix imgu for all public APIs, i.e. change ipu3_v4l2_register() to imgu_v4l2_register(). (Sakari) -- Use V4L2_CTRL_TYPE_MENU for dual-pipe mode control. (Sakari) - - IPU3 driver documentation (Laurent) Add diagram in driver rst to describe output capability. Comments on configuring v4l2 subdevs for CIO2 and ImgU. diff --git a/drivers/staging/media/ipu3/include/intel-ipu3.h b/drivers/staging/media/ipu3/include/intel-ipu3.h index ec0b74829351..eb6f52aca992 100644 --- a/drivers/staging/media/ipu3/include/intel-ipu3.h +++ b/drivers/staging/media/ipu3/include/intel-ipu3.h @@ -16,12 +16,6 @@ #define V4L2_CID_INTEL_IPU3_BASE (V4L2_CID_USER_BASE + 0x10c0) #define V4L2_CID_INTEL_IPU3_MODE (V4L2_CID_INTEL_IPU3_BASE + 1) -/* custom ctrl to set pipe mode */ -enum ipu3_running_mode { - IPU3_RUNNING_MODE_VIDEO = 0, - IPU3_RUNNING_MODE_STILL = 1, -}; - /*** ipu3_uapi_stats_3a ***/ #define IPU3_UAPI_MAX_STRIPES 2 diff --git a/drivers/staging/media/ipu3/ipu3-v4l2.c b/drivers/staging/media/ipu3/ipu3-v4l2.c index c7936032beb9..d2a0b62d5688 100644 --- a/drivers/staging/media/ipu3/ipu3-v4l2.c +++ b/drivers/staging/media/ipu3/ipu3-v4l2.c @@ -12,6 +12,9 @@ / v4l2_subdev_ops / +#defineIPU3_RUNNING_MODE_VIDEO 0 +#defineIPU3_RUNNING_MODE_STILL 1 + static int ipu3_subdev_open(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh) { struct imgu_v4l2_subdev *imgu_sd = container_of(sd, @@ -1035,15 +1038,20 @@ static const struct v4l2_ctrl_ops ipu3_subdev_ctrl_ops = { .s_ctrl = ipu3_sd_s_ctrl, }; +static const char * const ipu3_ctrl_mode_strings[] = { + "Video mode", + "Still mode", + NULL, +}; + static const struct v4l2_ctrl_config ipu3_subdev_ctrl_mode = { .ops = &ipu3_subdev_ctrl_ops, .id = V4L2_CID_INTEL_IPU3_MODE, .name = "IPU3 Pipe Mode", - .type = V4L2_CTRL_TYPE_INTEGER, - .min = IPU3_RUNNING_MODE_VIDEO, - .max = IPU3_RUNNING_MODE_STILL, - .step = 1, - .def = IPU3_RUNNING_MODE_VIDEO, + .type = V4L2_CTRL_TYPE_MENU, + .max = ARRAY_SIZE(ipu3_ctrl_mode_strings) - 2, + .def = 0, + .qmenu = ipu3_ctrl_mode_strings, }; / Framework registration / -- 2.7.4
[PATCH 2/2] media: ipu3-imgu: Remove dead code for NULL check
Since ipu3_css_buf_dequeue() never returns NULL, remove the dead code to fix static checker warning: drivers/staging/media/ipu3/ipu3.c:493 imgu_isr_threaded() warn: 'b' is an error pointer or valid Signed-off-by: Yong Zhi --- Link to Dan's bug report: https://www.spinics.net/lists/linux-media/msg145043.html drivers/staging/media/ipu3/ipu3.c | 11 +-- 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/drivers/staging/media/ipu3/ipu3.c b/drivers/staging/media/ipu3/ipu3.c index d521b3afb8b1..839d9398f8e9 100644 --- a/drivers/staging/media/ipu3/ipu3.c +++ b/drivers/staging/media/ipu3/ipu3.c @@ -489,12 +489,11 @@ static irqreturn_t imgu_isr_threaded(int irq, void *imgu_ptr) mutex_unlock(&imgu->lock); } while (PTR_ERR(b) == -EAGAIN); - if (IS_ERR_OR_NULL(b)) { - if (!b || PTR_ERR(b) == -EBUSY) /* All done */ - break; - dev_err(&imgu->pci_dev->dev, - "failed to dequeue buffers (%ld)\n", - PTR_ERR(b)); + if (IS_ERR(b)) { + if (PTR_ERR(b) != -EBUSY) /* All done */ + dev_err(&imgu->pci_dev->dev, + "failed to dequeue buffers (%ld)\n", + PTR_ERR(b)); break; } -- 2.7.4
[PATCH] media: ipu3: update meta format documentation
Make changes based on Laurent's v8 review: https://www.spinics.net/lists/linux-media/msg144408.html Signed-off-by: Yong Zhi --- Documentation/media/uapi/v4l/meta-formats.rst | 2 +- .../media/uapi/v4l/pixfmt-meta-intel-ipu3.rst | 119 ++--- Documentation/media/v4l-drivers/ipu3.rst | 147 + 3 files changed, 159 insertions(+), 109 deletions(-) diff --git a/Documentation/media/uapi/v4l/meta-formats.rst b/Documentation/media/uapi/v4l/meta-formats.rst index 5f956fa784b7..b10ca9ee3968 100644 --- a/Documentation/media/uapi/v4l/meta-formats.rst +++ b/Documentation/media/uapi/v4l/meta-formats.rst @@ -19,8 +19,8 @@ These formats are used for the :ref:`metadata` interface only. .. toctree:: :maxdepth: 1 -pixfmt-meta-intel-ipu3 pixfmt-meta-d4xx +pixfmt-meta-intel-ipu3 pixfmt-meta-uvc pixfmt-meta-vsp1-hgo pixfmt-meta-vsp1-hgt diff --git a/Documentation/media/uapi/v4l/pixfmt-meta-intel-ipu3.rst b/Documentation/media/uapi/v4l/pixfmt-meta-intel-ipu3.rst index dc871006b41a..a5ae21da9974 100644 --- a/Documentation/media/uapi/v4l/pixfmt-meta-intel-ipu3.rst +++ b/Documentation/media/uapi/v4l/pixfmt-meta-intel-ipu3.rst @@ -7,21 +7,22 @@ V4L2_META_FMT_IPU3_PARAMS ('ip3p'), V4L2_META_FMT_IPU3_3A ('ip3s') ** -.. c:type:: ipu3_uapi_stats_3a +.. ipu3_uapi_stats_3a 3A statistics = -For IPU3 ImgU, the 3A statistics accelerators collect different statistics over -an input bayer frame. Those statistics, defined in data struct :c:type:`ipu3_uapi_stats_3a`, -are obtained from "ipu3-imgu 3a stat" metadata capture video node, which are then -passed to user space for statistics analysis using :c:type:`v4l2_meta_format` interface. +The IPU3 ImgU 3A statistics accelerators collect different statistics over +an input Bayer frame. Those statistics are obtained from the "ipu3-imgu [01] 3a +stat" metadata capture video nodes, using the :c:type:`v4l2_meta_format` +interface. They are formatted as described by the :c:type:`ipu3_uapi_stats_3a` +structure. The statistics collected are AWB (Auto-white balance) RGBS (Red, Green, Blue and Saturation measure) cells, AWB filter response, AF (Auto-focus) filter response, and AE (Auto-exposure) histogram. -struct :c:type:`ipu3_uapi_4a_config` saves configurable parameters for all above. +The struct :c:type:`ipu3_uapi_4a_config` saves all configurable parameters. .. code-block:: c @@ -37,105 +38,14 @@ struct :c:type:`ipu3_uapi_4a_config` saves configurable parameters for all above struct ipu3_uapi_ff_status stats_3a_status; }; -.. c:type:: ipu3_uapi_params +.. ipu3_uapi_params Pipeline parameters === -IPU3 pipeline has a number of image processing stages, each of which takes a -set of parameters as input. The major stages of pipelines are shown here: - -Raw pixels -> Bayer Downscaling -> Optical Black Correction -> - -Linearization -> Lens Shading Correction -> White Balance / Exposure / - -Focus Apply -> Bayer Noise Reduction -> ANR -> Demosaicing -> Color - -Correction Matrix -> Gamma correction -> Color Space Conversion -> - -Chroma Down Scaling -> Chromatic Noise Reduction -> Total Color - -Correction -> XNR3 -> TNR -> DDR - -The table below presents a description of the above algorithms. - - === -NameDescription - === -Optical Black Correction Optical Black Correction block subtracts a pre-defined -value from the respective pixel values to obtain better -image quality. -Defined in :c:type:`ipu3_uapi_obgrid_param`. -Linearization This algo block uses linearization parameters to -address non-linearity sensor effects. The Lookup table -table is defined in -:c:type:`ipu3_uapi_isp_lin_vmem_params`. -SHD Lens shading correction is used to correct spatial -non-uniformity of the pixel response due to optical -lens shading. This is done by applying a different gain -for each pixel. The gain, black level etc are -configured in :c:type:`ipu3_uapi_shd_config_static`. -BNR Bayer noise reduction block removes image noise by -applying a bilateral filter. -See :c:type:`ipu3_uapi_bnr_static_config` for details. -ANR Advanced Noise Reduction is a block based algorithm -that performs noise reduction in the Bayer domain. The
RE: [PATCH v8 15/17] media: v4l: Add Intel IPU3 meta buffer formats
Hi, Laurent, Thanks for the review. > -Original Message- > From: Laurent Pinchart [mailto:laurent.pinch...@ideasonboard.com] > Sent: Tuesday, December 11, 2018 6:59 AM > To: Zhi, Yong > Cc: linux-media@vger.kernel.org; sakari.ai...@linux.intel.com; > tf...@chromium.org; Mani, Rajmohan ; > Toivonen, Tuukka ; Hu, Jerry W > ; Qiu, Tian Shu ; > hans.verk...@cisco.com; mche...@kernel.org; Cao, Bingbu > ; Zheng, Jian Xu > Subject: Re: [PATCH v8 15/17] media: v4l: Add Intel IPU3 meta buffer formats > > Hello Yong, > > Thank you for the patch. > > On Friday, 7 December 2018 03:03:40 EET Yong Zhi wrote: > > Add IPU3-specific meta formats for processing parameters and 3A > > statistics. > > > > V4L2_META_FMT_IPU3_PARAMS > > V4L2_META_FMT_IPU3_STAT_3A > > > > Signed-off-by: Yong Zhi > > Reviewed-by: Laurent Pinchart > > My Reviewed-by tag was related to the format part only (v4l2-ioctl.c and > videodev2.h) :-) Please see below for more comments about the > documentation. > > > --- > > Documentation/media/uapi/v4l/meta-formats.rst | 1 + > > .../media/uapi/v4l/pixfmt-meta-intel-ipu3.rst | 178 > ++ > > drivers/media/v4l2-core/v4l2-ioctl.c | 2 + > > include/uapi/linux/videodev2.h | 4 + > > 4 files changed, 185 insertions(+) > > create mode 100644 > > Documentation/media/uapi/v4l/pixfmt-meta-intel-ipu3.rst > > > > diff --git a/Documentation/media/uapi/v4l/meta-formats.rst > > b/Documentation/media/uapi/v4l/meta-formats.rst index > > 438bd244bd2f..5f956fa784b7 100644 > > --- a/Documentation/media/uapi/v4l/meta-formats.rst > > +++ b/Documentation/media/uapi/v4l/meta-formats.rst > > @@ -19,6 +19,7 @@ These formats are used for the :ref:`metadata` > > interface only. > > .. toctree:: > > :maxdepth: 1 > > > > +pixfmt-meta-intel-ipu3 > > pixfmt-meta-d4xx > > pixfmt-meta-uvc > > pixfmt-meta-vsp1-hgo > > Please keep this list alphabetically sorted. > Ack. > > diff --git a/Documentation/media/uapi/v4l/pixfmt-meta-intel-ipu3.rst > > b/Documentation/media/uapi/v4l/pixfmt-meta-intel-ipu3.rst new file > > mode > > 100644 > > index ..8cd30ffbf8b8 > > --- /dev/null > > +++ b/Documentation/media/uapi/v4l/pixfmt-meta-intel-ipu3.rst > > @@ -0,0 +1,178 @@ > > +.. -*- coding: utf-8; mode: rst -*- > > + > > +.. _v4l2-meta-fmt-params: > > +.. _v4l2-meta-fmt-stat-3a: > > + > > > +*** > *** > > +V4L2_META_FMT_IPU3_PARAMS ('ip3p'), V4L2_META_FMT_IPU3_3A > ('ip3s') > > > +*** > *** > > + > > +.. c:type:: ipu3_uapi_stats_3a > > No need for c:type:: here, the structure is already properly defined in > drivers/staging/media/ipu3/include/intel-ipu3.h > Ack. > > +3A statistics > > += > > + > > +For IPU3 ImgU, the 3A statistics accelerators collect different > > +statistics > > I'd write "The IPU3 ImgU 3A statistics accelerators collect" or "The IPU3 ImgU > includes 3A statistics accelerators that collect" > > > over +an input bayer frame. Those statistics, defined in data struct > > bayer should be spelled Bayer (here and below). > > > :c:type:`ipu3_uapi_stats_3a`, +are obtained from "ipu3-imgu 3a stat" > > metadata capture video node, which are then +passed to user space for > > statistics analysis using :c:type:`v4l2_meta_format` interface. > > How about simply > > "Those statistics are obtained from the "ipu3-imgu [01] 3a stat" metadata > capture video nodes, using the :c:type:`v4l2_meta_format` interface. They > are formatted as described by the :c:type:`ipu3_uapi_stats_3a` structure." > Thanks for refining and improving the text :) > > + > > +The statistics collected are AWB (Auto-white balance) RGBS (Red, > > +Green, > > Blue and +Saturation measure) cells, AWB filter response, AF > > (Auto-focus) filter response, +and AE (Auto-exposure) histogram. > > Could you please wrap lines at the 80 columns boundary ? > Ack. > > +struct :c:type:`ipu3_uapi_4a_config` saves configurable parameters > > +for all > > above. > > I would write it as "The > > By the way why "4a" when the documentation talks about 3A ? Shouldn't the > structure be called ipu3_uapi_3a_config ? > The 4th "a" refers to the AWB filter
RE: [bug report] media: staging/intel-ipu3: Add imgu top level pci device driver
Cc Tianshu and others. Hi, Dan, Thanks a lot for the code review. > -Original Message- > From: Dan Carpenter [mailto:dan.carpen...@oracle.com] > Sent: Friday, January 4, 2019 6:29 AM > To: Zhi, Yong > Cc: linux-media@vger.kernel.org > Subject: [bug report] media: staging/intel-ipu3: Add imgu top level pci device > driver > > Hello Yong Zhi, > > The patch 7fc7af649ca7: "media: staging/intel-ipu3: Add imgu top level pci > device driver" from Dec 6, 2018, leads to the following static checker > warning: > > drivers/staging/media/ipu3/ipu3.c:493 imgu_isr_threaded() > warn: 'b' is an error pointer or valid > > drivers/staging/media/ipu3/ipu3.c > 472 static irqreturn_t imgu_isr_threaded(int irq, void *imgu_ptr) > 473 { > 474 struct imgu_device *imgu = imgu_ptr; > 475 struct imgu_media_pipe *imgu_pipe; > 476 int p; > 477 > 478 /* Dequeue / queue buffers */ > 479 do { > 480 u64 ns = ktime_get_ns(); > 481 struct ipu3_css_buffer *b; > 482 struct imgu_buffer *buf = NULL; > 483 unsigned int node, pipe; > 484 bool dummy; > 485 > 486 do { > 487 mutex_lock(&imgu->lock); > 488 b = ipu3_css_buf_dequeue(&imgu->css); > > ipu3_css_buf_dequeue() doesn't return NULL. > > 489 mutex_unlock(&imgu->lock); > 490 } while (PTR_ERR(b) == -EAGAIN); > 491 > 492 if (IS_ERR_OR_NULL(b)) { > ^ > --> 493 if (!b || PTR_ERR(b) == -EBUSY) /* All done */ > ^^ > When a function returns both NULL and error pointers, then NULL is > considered a special case of success. Like perhaps you request a feature, but > that feature isn't enabled in the config. It's fine, because the user > *chose* to > turn off the feature, so it's not an error but we also don't have a valid > pointer > we can use. > > It looks like you were probably trying to do something like that but you > missed part of the commit? Otherwise we should delete the dead code. > Ack, with recent code changes the NULL check becomes useless, thanks for catching this. > 494 break; > 495 dev_err(&imgu->pci_dev->dev, > 496 "failed to dequeue buffers (%ld)\n", > 497 PTR_ERR(b)); > 498 break; > 499 } > 500 > > regards, > dan carpenter
RE: [PATCH 1/1] media: staging/intel-ipu3: Fix Kconfig for unmet direct dependencies
Hi, Sakari, > -Original Message- > From: Sakari Ailus [mailto:sakari.ai...@linux.intel.com] > Sent: Wednesday, January 2, 2019 2:11 PM > To: Zhi, Yong > Cc: linux-media@vger.kernel.org; tf...@chromium.org; Mani, Rajmohan > ; hans.verk...@cisco.com; > mche...@kernel.org; laurent.pinch...@ideasonboard.com; Cao, Bingbu > ; Qiu, Tian Shu > Subject: Re: [PATCH 1/1] media: staging/intel-ipu3: Fix Kconfig for unmet > direct dependencies > > Hi Yong, > > On Mon, Dec 31, 2018 at 11:46:43AM -0600, Yong Zhi wrote: > > Fix link error for specific .config reported by lkp robot: > > > > drivers/staging/media/ipu3/ipu3-dmamap.o: In function > `ipu3_dmamap_alloc': > > drivers/staging/media/ipu3/ipu3-dmamap.c:111: undefined reference to > `alloc_iova' > > > > Signed-off-by: Yong Zhi > > --- > > Happy New Year!! > > > > drivers/staging/media/ipu3/Kconfig | 2 +- > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > diff --git a/drivers/staging/media/ipu3/Kconfig > > b/drivers/staging/media/ipu3/Kconfig > > index 75cd889f18f7..c486cbbe859a 100644 > > --- a/drivers/staging/media/ipu3/Kconfig > > +++ b/drivers/staging/media/ipu3/Kconfig > > @@ -3,7 +3,7 @@ config VIDEO_IPU3_IMGU > > depends on PCI && VIDEO_V4L2 > > depends on MEDIA_CONTROLLER && VIDEO_V4L2_SUBDEV_API > > depends on X86 > > - select IOMMU_IOVA > > + select IOMMU_IOVA if IOMMU_SUPPORT > > I don't think this really addresses the issue: the IOVA library is needed in > any > case. I'll submit a patch... > Sure, thanks!! > > select VIDEOBUF2_DMA_SG > > ---help--- > > This is the Video4Linux2 driver for Intel IPU3 image processing > > unit, > > -- > > 2.7.4 > > > > -- > Sakari Ailus > sakari.ai...@linux.intel.com
[PATCH 1/1] media: staging/intel-ipu3: Fix Kconfig for unmet direct dependencies
Fix link error for specific .config reported by lkp robot: drivers/staging/media/ipu3/ipu3-dmamap.o: In function `ipu3_dmamap_alloc': drivers/staging/media/ipu3/ipu3-dmamap.c:111: undefined reference to `alloc_iova' Signed-off-by: Yong Zhi --- Happy New Year!! drivers/staging/media/ipu3/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/staging/media/ipu3/Kconfig b/drivers/staging/media/ipu3/Kconfig index 75cd889f18f7..c486cbbe859a 100644 --- a/drivers/staging/media/ipu3/Kconfig +++ b/drivers/staging/media/ipu3/Kconfig @@ -3,7 +3,7 @@ config VIDEO_IPU3_IMGU depends on PCI && VIDEO_V4L2 depends on MEDIA_CONTROLLER && VIDEO_V4L2_SUBDEV_API depends on X86 - select IOMMU_IOVA + select IOMMU_IOVA if IOMMU_SUPPORT select VIDEOBUF2_DMA_SG ---help--- This is the Video4Linux2 driver for Intel IPU3 image processing unit, -- 2.7.4
Re: [linux-sunxi] [PATCH v12 0/2] Initial Allwinner V3s CSI Support
Hi, On Wed, 26 Dec 2018 11:29:36 +0100 'Ondřej Jirman' via linux-sunxi wrote: > Hello, > > On Tue, Oct 30, 2018 at 04:09:48PM +0800, Yong Deng wrote: > > I can't make v4l2-compliance always happy. > > The V3s CSI support many pixformats. But they are not always available. > > It's dependent on the input bus format (MEDIA_BUS_FMT_*). > > Example: > > V4L2_PIX_FMT_SBGGR8: MEDIA_BUS_FMT_SBGGR8_1X8 > > V4L2_PIX_FMT_YUYV: MEDIA_BUS_FMT_YUYV8_2X8 > > But I can't get the subdev's format code before starting stream as the > > subdev may change it. So I can't know which pixformats are available. > > So I exports all the pixformats supported by SoC. > > The result is the app (v4l2-compliance) is likely to fail on streamon. > > > > This patchset add initial support for Allwinner V3s CSI. > > I've tested your patches on A83T and CSI works on that SoC too. I'll send > DTS patches later. > > One thing I noticed is that, when you cat the regmap registers file in debugfs > while streaming, the kernel locks up hard. I was not able to extract any logs. May be some registers can't be read when streaming ? Like read-clear regs ? Or multi CPU core access regs at the same time may cause the bus lock up? Thanks, Yong
[PATCH v8 15/17] media: v4l: Add Intel IPU3 meta buffer formats
Add IPU3-specific meta formats for processing parameters and 3A statistics. V4L2_META_FMT_IPU3_PARAMS V4L2_META_FMT_IPU3_STAT_3A Signed-off-by: Yong Zhi Reviewed-by: Laurent Pinchart --- Documentation/media/uapi/v4l/meta-formats.rst | 1 + .../media/uapi/v4l/pixfmt-meta-intel-ipu3.rst | 178 + drivers/media/v4l2-core/v4l2-ioctl.c | 2 + include/uapi/linux/videodev2.h | 4 + 4 files changed, 185 insertions(+) create mode 100644 Documentation/media/uapi/v4l/pixfmt-meta-intel-ipu3.rst diff --git a/Documentation/media/uapi/v4l/meta-formats.rst b/Documentation/media/uapi/v4l/meta-formats.rst index 438bd244bd2f..5f956fa784b7 100644 --- a/Documentation/media/uapi/v4l/meta-formats.rst +++ b/Documentation/media/uapi/v4l/meta-formats.rst @@ -19,6 +19,7 @@ These formats are used for the :ref:`metadata` interface only. .. toctree:: :maxdepth: 1 +pixfmt-meta-intel-ipu3 pixfmt-meta-d4xx pixfmt-meta-uvc pixfmt-meta-vsp1-hgo diff --git a/Documentation/media/uapi/v4l/pixfmt-meta-intel-ipu3.rst b/Documentation/media/uapi/v4l/pixfmt-meta-intel-ipu3.rst new file mode 100644 index ..8cd30ffbf8b8 --- /dev/null +++ b/Documentation/media/uapi/v4l/pixfmt-meta-intel-ipu3.rst @@ -0,0 +1,178 @@ +.. -*- coding: utf-8; mode: rst -*- + +.. _v4l2-meta-fmt-params: +.. _v4l2-meta-fmt-stat-3a: + +** +V4L2_META_FMT_IPU3_PARAMS ('ip3p'), V4L2_META_FMT_IPU3_3A ('ip3s') +** + +.. c:type:: ipu3_uapi_stats_3a + +3A statistics += + +For IPU3 ImgU, the 3A statistics accelerators collect different statistics over +an input bayer frame. Those statistics, defined in data struct :c:type:`ipu3_uapi_stats_3a`, +are obtained from "ipu3-imgu 3a stat" metadata capture video node, which are then +passed to user space for statistics analysis using :c:type:`v4l2_meta_format` interface. + +The statistics collected are AWB (Auto-white balance) RGBS (Red, Green, Blue and +Saturation measure) cells, AWB filter response, AF (Auto-focus) filter response, +and AE (Auto-exposure) histogram. + +struct :c:type:`ipu3_uapi_4a_config` saves configurable parameters for all above. + +.. code-block:: c + + struct ipu3_uapi_stats_3a { + struct ipu3_uapi_awb_raw_buffer awb_raw_buffer; + struct ipu3_uapi_ae_raw_buffer_aligned ae_raw_buffer[IPU3_UAPI_MAX_STRIPES]; + struct ipu3_uapi_af_raw_buffer af_raw_buffer; + struct ipu3_uapi_awb_fr_raw_buffer awb_fr_raw_buffer; + struct ipu3_uapi_4a_config stats_4a_config; + __u32 ae_join_buffers; + __u8 padding[28]; + struct ipu3_uapi_stats_3a_bubble_info_per_stripe stats_3a_bubble_per_stripe; + struct ipu3_uapi_ff_status stats_3a_status; + }; + +.. c:type:: ipu3_uapi_params + +Pipeline parameters +=== + +IPU3 pipeline has a number of image processing stages, each of which takes a +set of parameters as input. The major stages of pipelines are shown here: + +Raw pixels -> Bayer Downscaling -> Optical Black Correction -> + +Linearization -> Lens Shading Correction -> White Balance / Exposure / + +Focus Apply -> Bayer Noise Reduction -> ANR -> Demosaicing -> Color + +Correction Matrix -> Gamma correction -> Color Space Conversion -> + +Chroma Down Scaling -> Chromatic Noise Reduction -> Total Color + +Correction -> XNR3 -> TNR -> DDR + +The table below presents a description of the above algorithms. + + === +NameDescription + === +Optical Black Correction Optical Black Correction block subtracts a pre-defined +value from the respective pixel values to obtain better +image quality. +Defined in :c:type:`ipu3_uapi_obgrid_param`. +Linearization This algo block uses linearization parameters to +address non-linearity sensor effects. The Lookup table +table is defined in +:c:type:`ipu3_uapi_isp_lin_vmem_params`. +SHD Lens shading correction is used to correct spatial +non-uniformity of the pixel response due to optical +lens shading. This is done by applying a different gain +for each pixel. The gain, black level etc are +configured in :c:type:`ipu3_uapi_shd_config_static`. +BNR Bayer noise reduction block removes image noise by +applying a bilateral filter. +
[PATCH v8 12/17] media: staging/intel-ipu3: Add imgu top level pci device driver
This patch adds support for the Intel IPU v3 as found on Skylake and Kaby Lake SoCs. The driver glues v4l2, css(camera sub system) and other pieces together to perform its functions, it also loads the IPU3 firmware binary as part of its initialization. Signed-off-by: Yong Zhi Signed-off-by: Tomasz Figa --- drivers/staging/media/Kconfig | 2 + drivers/staging/media/Makefile | 1 + drivers/staging/media/ipu3/Kconfig | 14 + drivers/staging/media/ipu3/Makefile | 11 + drivers/staging/media/ipu3/TODO | 23 + drivers/staging/media/ipu3/ipu3.c | 844 drivers/staging/media/ipu3/ipu3.h | 152 +++ 7 files changed, 1047 insertions(+) create mode 100644 drivers/staging/media/ipu3/Kconfig create mode 100644 drivers/staging/media/ipu3/Makefile create mode 100644 drivers/staging/media/ipu3/TODO create mode 100644 drivers/staging/media/ipu3/ipu3.c create mode 100644 drivers/staging/media/ipu3/ipu3.h diff --git a/drivers/staging/media/Kconfig b/drivers/staging/media/Kconfig index c6f3404dea43..19cadd17e542 100644 --- a/drivers/staging/media/Kconfig +++ b/drivers/staging/media/Kconfig @@ -39,4 +39,6 @@ source "drivers/staging/media/tegra-vde/Kconfig" source "drivers/staging/media/zoran/Kconfig" +source "drivers/staging/media/ipu3/Kconfig" + endif diff --git a/drivers/staging/media/Makefile b/drivers/staging/media/Makefile index 43c7bee1fc8c..edde1960b030 100644 --- a/drivers/staging/media/Makefile +++ b/drivers/staging/media/Makefile @@ -9,3 +9,4 @@ obj-$(CONFIG_VIDEO_SUNXI) += sunxi/ obj-$(CONFIG_TEGRA_VDE)+= tegra-vde/ obj-$(CONFIG_VIDEO_ZORAN) += zoran/ obj-$(CONFIG_VIDEO_ROCKCHIP_VPU) += rockchip/vpu/ +obj-$(CONFIG_VIDEO_IPU3_IMGU) += ipu3/ diff --git a/drivers/staging/media/ipu3/Kconfig b/drivers/staging/media/ipu3/Kconfig new file mode 100644 index ..75cd889f18f7 --- /dev/null +++ b/drivers/staging/media/ipu3/Kconfig @@ -0,0 +1,14 @@ +config VIDEO_IPU3_IMGU + tristate "Intel ipu3-imgu driver" + depends on PCI && VIDEO_V4L2 + depends on MEDIA_CONTROLLER && VIDEO_V4L2_SUBDEV_API + depends on X86 + select IOMMU_IOVA + select VIDEOBUF2_DMA_SG + ---help--- + This is the Video4Linux2 driver for Intel IPU3 image processing unit, + found in Intel Skylake and Kaby Lake SoCs and used for processing + images and video. + + Say Y or M here if you have a Skylake/Kaby Lake SoC with a MIPI + camera. The module will be called ipu3-imgu. diff --git a/drivers/staging/media/ipu3/Makefile b/drivers/staging/media/ipu3/Makefile new file mode 100644 index ..fb146d178bd4 --- /dev/null +++ b/drivers/staging/media/ipu3/Makefile @@ -0,0 +1,11 @@ +# +# Makefile for the IPU3 ImgU drivers +# + +ipu3-imgu-objs += \ + ipu3-mmu.o ipu3-dmamap.o \ + ipu3-tables.o ipu3-css-pool.o \ + ipu3-css-fw.o ipu3-css-params.o \ + ipu3-css.o ipu3-v4l2.o ipu3.o + +obj-$(CONFIG_VIDEO_IPU3_IMGU) += ipu3-imgu.o diff --git a/drivers/staging/media/ipu3/TODO b/drivers/staging/media/ipu3/TODO new file mode 100644 index ..922b885f10a7 --- /dev/null +++ b/drivers/staging/media/ipu3/TODO @@ -0,0 +1,23 @@ +This is a list of things that need to be done to get this driver out of the +staging directory. + +- Request API conversion. Remove of the dual pipeline and associate buffers + as well as formats and the binary used to a request. Remove the + opportunistic buffer management. (Sakari) + +- Using ENABLED and IMMUTABLE link flags for the links where those are + relevant. (Sakari) + +- Prefix imgu for all public APIs, i.e. change ipu3_v4l2_register() to + imgu_v4l2_register(). (Sakari) + +- Use V4L2_CTRL_TYPE_MENU for dual-pipe mode control. (Sakari) + +- IPU3 driver documentation (Laurent) + Add diagram in driver rst to describe output capability. + Comments on configuring v4l2 subdevs for CIO2 and ImgU. + +- uAPI documentation: + Further clarification on some ambiguities such as data type conversion of + IEFD CU inputs. (Sakari) + Move acronyms to doc-rst file. (Mauro) diff --git a/drivers/staging/media/ipu3/ipu3.c b/drivers/staging/media/ipu3/ipu3.c new file mode 100644 index ..3d0a34b86ff4 --- /dev/null +++ b/drivers/staging/media/ipu3/ipu3.c @@ -0,0 +1,844 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (C) 2017 - 2018 Intel Corporation + * Copyright 2017 Google LLC + * + * Based on Intel IPU4 driver. + * + */ + +#include +#include +#include +#include + +#include "ipu3.h" +#include "ipu3-dmamap.h" +#include "ipu3-mmu.h" + +#define IMGU_PCI_ID0x1919 +#define IMGU_PCI_BAR 0 +#define IMGU_DMA_MASK DMA_BIT_MASK(39) +#define IMGU_MAX_QUEUE_DEPTH (2 + 2) + +/* + * pre-allocated buffer size for IMGU dummy buf
[PATCH v8 08/17] media: staging/intel-ipu3: css: Compute and program ccs
A collection of routines that are mainly used to calculate the parameters for accelerator cluster. Signed-off-by: Yong Zhi --- drivers/staging/media/ipu3/ipu3-css-params.c | 2915 ++ drivers/staging/media/ipu3/ipu3-css-params.h | 25 + 2 files changed, 2940 insertions(+) create mode 100644 drivers/staging/media/ipu3/ipu3-css-params.c create mode 100644 drivers/staging/media/ipu3/ipu3-css-params.h diff --git a/drivers/staging/media/ipu3/ipu3-css-params.c b/drivers/staging/media/ipu3/ipu3-css-params.c new file mode 100644 index ..747352c089dd --- /dev/null +++ b/drivers/staging/media/ipu3/ipu3-css-params.c @@ -0,0 +1,2915 @@ +// SPDX-License-Identifier: GPL-2.0 +// Copyright (C) 2018 Intel Corporation + +#include + +#include "ipu3-css.h" +#include "ipu3-css-fw.h" +#include "ipu3-tables.h" + +#define DIV_ROUND_CLOSEST_DOWN(a, b) (((a) + ((b) / 2) - 1) / (b)) +#define roundclosest_down(a, b)(DIV_ROUND_CLOSEST_DOWN(a, b) * (b)) + +#define IPU3_UAPI_ANR_MAX_RESET((1 << 12) - 1) +#define IPU3_UAPI_ANR_MIN_RESET(((-1) << 12) + 1) + +struct ipu3_css_scaler_info { + unsigned int phase_step;/* Same for luma/chroma */ + int exp_shift; + + unsigned int phase_init;/* luma/chroma dependent */ + int pad_left; + int pad_right; + int crop_left; + int crop_top; +}; + +static unsigned int ipu3_css_scaler_get_exp(unsigned int counter, + unsigned int divider) +{ + int i = fls(divider) - fls(counter); + + if (i <= 0) + return 0; + + if (divider >> i < counter) + i = i - 1; + + return i; +} + +/* Set up the CSS scaler look up table */ +static void +ipu3_css_scaler_setup_lut(unsigned int taps, unsigned int input_width, + unsigned int output_width, int phase_step_correction, + const int *coeffs, unsigned int coeffs_size, + s8 coeff_lut[], struct ipu3_css_scaler_info *info) +{ + int tap, phase, phase_sum_left, phase_sum_right; + int exponent = ipu3_css_scaler_get_exp(output_width, input_width); + int mantissa = (1 << exponent) * output_width; + unsigned int phase_step; + + if (input_width == output_width) { + for (phase = 0; phase < IMGU_SCALER_PHASES; phase++) { + for (tap = 0; tap < taps; tap++) { + coeff_lut[phase * IMGU_SCALER_FILTER_TAPS + tap] + = 0; + } + } + + info->phase_step = IMGU_SCALER_PHASES * + (1 << IMGU_SCALER_PHASE_COUNTER_PREC_REF); + info->exp_shift = 0; + info->pad_left = 0; + info->pad_right = 0; + info->phase_init = 0; + info->crop_left = 0; + info->crop_top = 0; + return; + } + + for (phase = 0; phase < IMGU_SCALER_PHASES; phase++) { + for (tap = 0; tap < taps; tap++) { + /* flip table to for convolution reverse indexing */ + s64 coeff = coeffs[coeffs_size - + ((tap * (coeffs_size / taps)) + phase) - 1]; + coeff *= mantissa; + coeff = div64_long(coeff, input_width); + + /* Add +"0.5" */ + coeff += 1 << (IMGU_SCALER_COEFF_BITS - 1); + coeff >>= IMGU_SCALER_COEFF_BITS; + + coeff_lut[phase * IMGU_SCALER_FILTER_TAPS + tap] = + coeff; + } + } + + phase_step = IMGU_SCALER_PHASES * + (1 << IMGU_SCALER_PHASE_COUNTER_PREC_REF) * + output_width / input_width; + phase_step += phase_step_correction; + phase_sum_left = (taps / 2 * IMGU_SCALER_PHASES * + (1 << IMGU_SCALER_PHASE_COUNTER_PREC_REF)) - + (1 << (IMGU_SCALER_PHASE_COUNTER_PREC_REF - 1)); + phase_sum_right = (taps / 2 * IMGU_SCALER_PHASES * + (1 << IMGU_SCALER_PHASE_COUNTER_PREC_REF)) + + (1 << (IMGU_SCALER_PHASE_COUNTER_PREC_REF - 1)); + + info->exp_shift = IMGU_SCALER_MAX_EXPONENT_SHIFT - exponent; + info->pad_left = (phase_sum_left % phase_step == 0) ? + phase_sum_left / phase_step - 1 : phase_sum_left / phase_step; + info->pad_right = (phase_sum_right % phase_step == 0) ? + phase_sum_right / phase_step - 1 : phase_sum_right / phase_step; + info->phase_init = phase_sum_left - phase_step * info->pad_le
[PATCH v8 06/17] media: staging/intel-ipu3: css: Add support for firmware management
Introduce functions to load and install ImgU FW blobs. Signed-off-by: Yong Zhi --- drivers/staging/media/ipu3/ipu3-css-fw.c | 264 +++ drivers/staging/media/ipu3/ipu3-css-fw.h | 188 ++ 2 files changed, 452 insertions(+) create mode 100644 drivers/staging/media/ipu3/ipu3-css-fw.c create mode 100644 drivers/staging/media/ipu3/ipu3-css-fw.h diff --git a/drivers/staging/media/ipu3/ipu3-css-fw.c b/drivers/staging/media/ipu3/ipu3-css-fw.c new file mode 100644 index ..ba459e98d77d --- /dev/null +++ b/drivers/staging/media/ipu3/ipu3-css-fw.c @@ -0,0 +1,264 @@ +// SPDX-License-Identifier: GPL-2.0 +// Copyright (C) 2018 Intel Corporation + +#include +#include +#include +#include + +#include "ipu3-css.h" +#include "ipu3-css-fw.h" +#include "ipu3-dmamap.h" + +static void ipu3_css_fw_show_binary(struct device *dev, struct imgu_fw_info *bi, + const char *name) +{ + unsigned int i; + + dev_dbg(dev, "found firmware binary type %i size %i name %s\n", + bi->type, bi->blob.size, name); + if (bi->type != IMGU_FW_ISP_FIRMWARE) + return; + + dev_dbg(dev, "id %i mode %i bds 0x%x veceven %i/%i out_pins %i\n", + bi->info.isp.sp.id, bi->info.isp.sp.pipeline.mode, + bi->info.isp.sp.bds.supported_bds_factors, + bi->info.isp.sp.enable.vf_veceven, + bi->info.isp.sp.vf_dec.is_variable, + bi->info.isp.num_output_pins); + + dev_dbg(dev, "input (%i,%i)-(%i,%i) formats %s%s%s\n", + bi->info.isp.sp.input.min_width, + bi->info.isp.sp.input.min_height, + bi->info.isp.sp.input.max_width, + bi->info.isp.sp.input.max_height, + bi->info.isp.sp.enable.input_yuv ? "yuv420 " : "", + bi->info.isp.sp.enable.input_feeder || + bi->info.isp.sp.enable.input_raw ? "raw8 raw10 " : "", + bi->info.isp.sp.enable.input_raw ? "raw12" : ""); + + dev_dbg(dev, "internal (%i,%i)\n", + bi->info.isp.sp.internal.max_width, + bi->info.isp.sp.internal.max_height); + + dev_dbg(dev, "output (%i,%i)-(%i,%i) formats", + bi->info.isp.sp.output.min_width, + bi->info.isp.sp.output.min_height, + bi->info.isp.sp.output.max_width, + bi->info.isp.sp.output.max_height); + for (i = 0; i < bi->info.isp.num_output_formats; i++) + dev_dbg(dev, " %i", bi->info.isp.output_formats[i]); + dev_dbg(dev, " vf"); + for (i = 0; i < bi->info.isp.num_vf_formats; i++) + dev_dbg(dev, " %i", bi->info.isp.vf_formats[i]); + dev_dbg(dev, "\n"); +} + +unsigned int ipu3_css_fw_obgrid_size(const struct imgu_fw_info *bi) +{ + unsigned int width = DIV_ROUND_UP(bi->info.isp.sp.internal.max_width, + IMGU_OBGRID_TILE_SIZE * 2) + 1; + unsigned int height = DIV_ROUND_UP(bi->info.isp.sp.internal.max_height, + IMGU_OBGRID_TILE_SIZE * 2) + 1; + unsigned int obgrid_size; + + width = ALIGN(width, IPU3_UAPI_ISP_VEC_ELEMS / 4); + obgrid_size = PAGE_ALIGN(width * height * +sizeof(struct ipu3_uapi_obgrid_param)) * +bi->info.isp.sp.iterator.num_stripes; + return obgrid_size; +} + +void *ipu3_css_fw_pipeline_params(struct ipu3_css *css, + enum imgu_abi_param_class c, + enum imgu_abi_memories m, + struct imgu_fw_isp_parameter *par, + size_t par_size, void *binary_params) +{ + struct imgu_fw_info *bi = &css->fwp->binary_header[css->current_binary]; + + if (par->offset + par->size > + bi->info.isp.sp.mem_initializers.params[c][m].size) + return NULL; + + if (par->size != par_size) + pr_warn("parameter size doesn't match defined size\n"); + + if (par->size < par_size) + return NULL; + + return binary_params + par->offset; +} + +void ipu3_css_fw_cleanup(struct ipu3_css *css) +{ + struct imgu_device *imgu = dev_get_drvdata(css->dev); + + if (css->binary) { + unsigned int i; + + for (i = 0; i < css->fwp->file_header.binary_nr; i++) + ipu3_dmamap_free(imgu, &css->binary[i]); + kfree(css->binary); + } + if (c
[PATCH v8 10/17] media: staging/intel-ipu3: Add css pipeline programming
This provides helper library to be used by v4l2 level to program imaging pipelines and control the streaming. Signed-off-by: Yong Zhi --- drivers/staging/media/ipu3/ipu3-css.c | 1740 + 1 file changed, 1740 insertions(+) diff --git a/drivers/staging/media/ipu3/ipu3-css.c b/drivers/staging/media/ipu3/ipu3-css.c index 164830fc91ad..3811ad752e8d 100644 --- a/drivers/staging/media/ipu3/ipu3-css.c +++ b/drivers/staging/media/ipu3/ipu3-css.c @@ -16,6 +16,173 @@ IMGU_IRQCTRL_IRQ_SW_PIN(0) | \ IMGU_IRQCTRL_IRQ_SW_PIN(1)) +#define IPU3_CSS_FORMAT_BPP_DEN50 /* Denominator */ + +/* Some sane limits for resolutions */ +#define IPU3_CSS_MIN_RES 32 +#define IPU3_CSS_MAX_H 3136 +#define IPU3_CSS_MAX_W 4224 + +/* filter size from graph settings is fixed as 4 */ +#define FILTER_SIZE 4 +#define MIN_ENVELOPE8 + +/* + * pre-allocated buffer size for CSS ABI, auxiliary frames + * after BDS and before GDC. Those values should be tuned + * to big enough to avoid buffer re-allocation when + * streaming to lower streaming latency. + */ +#define CSS_ABI_SIZE136 +#define CSS_BDS_SIZE(4480 * 3200 * 3) +#define CSS_GDC_SIZE(4224 * 3200 * 12 / 8) + +#define IPU3_CSS_QUEUE_TO_FLAGS(q) (1 << (q)) +#define IPU3_CSS_FORMAT_FL_IN \ + IPU3_CSS_QUEUE_TO_FLAGS(IPU3_CSS_QUEUE_IN) +#define IPU3_CSS_FORMAT_FL_OUT \ + IPU3_CSS_QUEUE_TO_FLAGS(IPU3_CSS_QUEUE_OUT) +#define IPU3_CSS_FORMAT_FL_VF \ + IPU3_CSS_QUEUE_TO_FLAGS(IPU3_CSS_QUEUE_VF) + +/* Formats supported by IPU3 Camera Sub System */ +static const struct ipu3_css_format ipu3_css_formats[] = { + { + .pixelformat = V4L2_PIX_FMT_NV12, + .colorspace = V4L2_COLORSPACE_SRGB, + .frame_format = IMGU_ABI_FRAME_FORMAT_NV12, + .osys_format = IMGU_ABI_OSYS_FORMAT_NV12, + .osys_tiling = IMGU_ABI_OSYS_TILING_NONE, + .bytesperpixel_num = 1 * IPU3_CSS_FORMAT_BPP_DEN, + .chroma_decim = 4, + .width_align = IPU3_UAPI_ISP_VEC_ELEMS, + .flags = IPU3_CSS_FORMAT_FL_OUT | IPU3_CSS_FORMAT_FL_VF, + }, { + /* Each 32 bytes contains 25 10-bit pixels */ + .pixelformat = V4L2_PIX_FMT_IPU3_SBGGR10, + .colorspace = V4L2_COLORSPACE_RAW, + .frame_format = IMGU_ABI_FRAME_FORMAT_RAW_PACKED, + .bayer_order = IMGU_ABI_BAYER_ORDER_BGGR, + .bit_depth = 10, + .bytesperpixel_num = 64, + .width_align = 2 * IPU3_UAPI_ISP_VEC_ELEMS, + .flags = IPU3_CSS_FORMAT_FL_IN, + }, { + .pixelformat = V4L2_PIX_FMT_IPU3_SGBRG10, + .colorspace = V4L2_COLORSPACE_RAW, + .frame_format = IMGU_ABI_FRAME_FORMAT_RAW_PACKED, + .bayer_order = IMGU_ABI_BAYER_ORDER_GBRG, + .bit_depth = 10, + .bytesperpixel_num = 64, + .width_align = 2 * IPU3_UAPI_ISP_VEC_ELEMS, + .flags = IPU3_CSS_FORMAT_FL_IN, + }, { + .pixelformat = V4L2_PIX_FMT_IPU3_SGRBG10, + .colorspace = V4L2_COLORSPACE_RAW, + .frame_format = IMGU_ABI_FRAME_FORMAT_RAW_PACKED, + .bayer_order = IMGU_ABI_BAYER_ORDER_GRBG, + .bit_depth = 10, + .bytesperpixel_num = 64, + .width_align = 2 * IPU3_UAPI_ISP_VEC_ELEMS, + .flags = IPU3_CSS_FORMAT_FL_IN, + }, { + .pixelformat = V4L2_PIX_FMT_IPU3_SRGGB10, + .colorspace = V4L2_COLORSPACE_RAW, + .frame_format = IMGU_ABI_FRAME_FORMAT_RAW_PACKED, + .bayer_order = IMGU_ABI_BAYER_ORDER_RGGB, + .bit_depth = 10, + .bytesperpixel_num = 64, + .width_align = 2 * IPU3_UAPI_ISP_VEC_ELEMS, + .flags = IPU3_CSS_FORMAT_FL_IN, + }, +}; + +static const struct { + enum imgu_abi_queue_id qid; + size_t ptr_ofs; +} ipu3_css_queues[IPU3_CSS_QUEUES] = { + [IPU3_CSS_QUEUE_IN] = { + IMGU_ABI_QUEUE_C_ID, + offsetof(struct imgu_abi_buffer, payload.frame.frame_data) + }, + [IPU3_CSS_QUEUE_OUT] = { + IMGU_ABI_QUEUE_D_ID, + offsetof(struct imgu_abi_buffer, payload.frame.frame_data) + }, + [IPU3_CSS_QUEUE_VF] = { + IMGU_ABI_QUEUE_E_ID, + offsetof(struct imgu_abi_buffer, payload.frame.frame_data) + }, + [IPU3_CSS_QUEUE_STAT_3A] = { + IMGU_ABI_QUEUE_F_ID, + offsetof(struct imgu_abi_buffer, payload.s3a.data_ptr) + }, +}; + +/* Initialize queue based on given format, adjust format as needed */ +static int ipu3_css_queue_init(struct ipu3_css_queue
[PATCH v8 01/17] media: staging/intel-ipu3: abi: Add register definitions and enum
Add macros and enums used for IPU3 firmware interface. Signed-off-by: Yong Zhi Signed-off-by: Rajmohan Mani Reviewed-by: Laurent Pinchart --- drivers/staging/media/ipu3/ipu3-abi.h | 661 ++ 1 file changed, 661 insertions(+) create mode 100644 drivers/staging/media/ipu3/ipu3-abi.h diff --git a/drivers/staging/media/ipu3/ipu3-abi.h b/drivers/staging/media/ipu3/ipu3-abi.h new file mode 100644 index ..e754ff5836c2 --- /dev/null +++ b/drivers/staging/media/ipu3/ipu3-abi.h @@ -0,0 +1,661 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* Copyright (C) 2018 Intel Corporation */ + +#ifndef __IPU3_ABI_H +#define __IPU3_ABI_H + +#include "include/intel-ipu3.h" + +/*** IMGU Hardware information ***/ + +typedef u32 imgu_addr_t; + +#define IMGU_ISP_VMEM_ALIGN128 +#define IMGU_DVS_BLOCK_W 64 +#define IMGU_DVS_BLOCK_H 32 +#define IMGU_GDC_BUF_X (2 * IMGU_DVS_BLOCK_W) +#define IMGU_GDC_BUF_Y IMGU_DVS_BLOCK_H +/* n = 0..1 */ +#define IMGU_SP_PMEM_BASE(n) (0x2 + (n) * 0x4000) +#define IMGU_MAX_BQ_GRID_WIDTH 80 +#define IMGU_MAX_BQ_GRID_HEIGHT60 +#define IMGU_OBGRID_TILE_SIZE 16 +#define IMGU_PIXELS_PER_WORD 50 +#define IMGU_BYTES_PER_WORD64 +#define IMGU_STRIPE_FIXED_HALF_OVERLAP 2 +#define IMGU_SHD_SETS 3 +#define IMGU_BDS_MIN_CLIP_VAL 0 +#define IMGU_BDS_MAX_CLIP_VAL 2 + +#define IMGU_ABI_AWB_MAX_CELLS_PER_SET 160 +#define IMGU_ABI_AF_MAX_CELLS_PER_SET 32 +#define IMGU_ABI_AWB_FR_MAX_CELLS_PER_SET 32 + +#define IMGU_ABI_ACC_OP_IDLE 0 +#define IMGU_ABI_ACC_OP_END_OF_ACK 1 +#define IMGU_ABI_ACC_OP_END_OF_OPS 2 +#define IMGU_ABI_ACC_OP_NO_OPS 3 + +#define IMGU_ABI_ACC_OPTYPE_PROCESS_LINES 0 +#define IMGU_ABI_ACC_OPTYPE_TRANSFER_DATA 1 + +/* Register definitions */ + +/* PM_CTRL_0_5_0_IMGHMMADR */ +#define IMGU_REG_PM_CTRL 0x0 +#define IMGU_PM_CTRL_START BIT(0) +#define IMGU_PM_CTRL_CFG_DONE BIT(1) +#define IMGU_PM_CTRL_RACE_TO_HALT BIT(2) +#define IMGU_PM_CTRL_NACK_ALL BIT(3) +#define IMGU_PM_CTRL_CSS_PWRDN BIT(4) +#define IMGU_PM_CTRL_RST_AT_EOFBIT(5) +#define IMGU_PM_CTRL_FORCE_HALTBIT(6) +#define IMGU_PM_CTRL_FORCE_UNHALT BIT(7) +#define IMGU_PM_CTRL_FORCE_PWRDN BIT(8) +#define IMGU_PM_CTRL_FORCE_RESET BIT(9) + +/* SYSTEM_REQ_0_5_0_IMGHMMADR */ +#define IMGU_REG_SYSTEM_REQ0x18 +#define IMGU_SYSTEM_REQ_FREQ_MASK 0x3f +#define IMGU_SYSTEM_REQ_FREQ_DIVIDER 25 +#define IMGU_REG_INT_STATUS0x30 +#define IMGU_REG_INT_ENABLE0x34 +#define IMGU_REG_INT_CSS_IRQ BIT(31) +/* STATE_0_5_0_IMGHMMADR */ +#define IMGU_REG_STATE 0x130 +#define IMGU_STATE_HALT_STSBIT(0) +#define IMGU_STATE_IDLE_STSBIT(1) +#define IMGU_STATE_POWER_UPBIT(2) +#define IMGU_STATE_POWER_DOWN BIT(3) +#define IMGU_STATE_CSS_BUSY_MASK 0xc0 +#define IMGU_STATE_PM_FSM_MASK 0x180 +#define IMGU_STATE_PWRDNM_FSM_MASK 0x1E0 +/* PM_STS_0_5_0_IMGHMMADR */ +#define IMGU_REG_PM_STS0x140 + +#define IMGU_REG_BASE 0x4000 + +#define IMGU_REG_ISP_CTRL (IMGU_REG_BASE + 0x00) +#define IMGU_CTRL_RST BIT(0) +#define IMGU_CTRL_STARTBIT(1) +#define IMGU_CTRL_BREAKBIT(2) +#define IMGU_CTRL_RUN BIT(3) +#define IMGU_CTRL_BROKEN BIT(4) +#define IMGU_CTRL_IDLE BIT(5) +#define IMGU_CTRL_SLEEPING BIT(6) +#define IMGU_CTRL_STALLING BIT(7) +#define IMGU_CTRL_IRQ_CLEARBIT(8) +#define IMGU_CTRL_IRQ_READYBIT(10) +#define IMGU_CTRL_IRQ_SLEEPING BIT(11) +#define IMGU_CTRL_ICACHE_INV BIT(12) +#define IMGU_CTRL_IPREFETCH_EN BIT(13) +#define IMGU_REG_ISP_START_ADDR(IMGU_REG_BASE + 0x04) +#define IMGU_REG_ISP_ICACHE_ADDR (IMGU_REG_BASE + 0x10) +#define IMGU_REG_ISP_PC(IMGU_REG_BASE + 0x1c) + +/* SP Registers, sp = 0:SP0; 1:SP1 */ +#define IMGU_REG_SP_CTRL(sp) (IMGU_REG_BASE + (sp) * 0x100 + 0x100) + /* For bits in IMGU_REG_SP_CTRL, see IMGU_CTRL_* *
[PATCH v8 00/17] Intel IPU3 ImgU patchset
NE format on video nodes. - ipu3-dmamap.c: Removed dma ops and dependencies on IOMMU_DMA lib. - ipu3-mmu.c: Restructured the driver. - intel-ipu3.h: Added __padding qualifier for uapi definitions. - Internal fix: power and performance related issues. - Fixed v4l2-compliance test. - Fixed build failure for x86 with 32bit config. version 3: - ipu3-mmu.c and ipu3-dmamap.c: Tomasz Figa reworked both drivers and updated related files. - ipu2-abi.h: update imgu_abi_binary_info ABI to support latest ipu3-fw.bin. use __packed qualifier on structs suggested by Sakari Ailus. - ipu3-css-fw.c/ipu3-css-fw.h: following fix were suggested by Tomasz Figa: remove pointer type in firmware blob structs. fix binary_header array in struct imgu_fw_header. fix calling ipu3_css_fw_show_binary() before proper checking. fix logic error for valid length checking of blob name. - ipu3-css-params.c/ipu3_css_scaler_get_exp(): use lib helper suggested by Andy Shevchenko. - ipu3-v4l2.c/ipu3_videoc_querycap(): fill device_caps fix suggested by Hans Verkuil. add VB2_DMABUF suggested by Tomasz Figa. - ipu3-css.c: increase IMGU freq from 300MHZ to 450MHZ (internal fix) - ipu3.c: use vb2_dma_sg_memop for the time being(internal fix). version 2: This version cherry-picked firmware ABI change and other fix in order to bring the code up-to-date with our internal release. I will go over the review comments in v1 and address them in v3 and future update. version 1: - Initial submission Cao,Bing Bu (2): media: staging/intel-ipu3: Add dual pipe support media: v4l2-ctrls: Reserve controls for IPU3 ImgU Rajmohan Mani (1): doc-rst: Add Intel IPU3 documentation Tomasz Figa (2): media: staging/intel-ipu3: mmu: Implement driver media: staging/intel-ipu3: Implement DMA mapping functions Yong Zhi (12): media: staging/intel-ipu3: abi: Add register definitions and enum media: staging/intel-ipu3: abi: Add structs media: staging/intel-ipu3: css: Add dma buff pool utility functions media: staging/intel-ipu3: css: Add support for firmware management media: staging/intel-ipu3: css: Add static settings for image pipeline media: staging/intel-ipu3: css: Compute and program ccs media: staging/intel-ipu3: css: Initialize css hardware media: staging/intel-ipu3: Add css pipeline programming media: staging/intel-ipu3: Add v4l2 driver based on media framework media: staging/intel-ipu3: Add imgu top level pci device driver media: staging/intel-ipu3: Add Intel IPU3 meta data uAPI media: v4l: Add Intel IPU3 meta buffer formats Documentation/media/uapi/v4l/meta-formats.rst |1 + .../media/uapi/v4l/pixfmt-meta-intel-ipu3.rst | 178 + Documentation/media/v4l-drivers/index.rst |1 + Documentation/media/v4l-drivers/ipu3.rst | 326 + drivers/media/v4l2-core/v4l2-ioctl.c |2 + drivers/staging/media/Kconfig |2 + drivers/staging/media/Makefile |1 + drivers/staging/media/ipu3/Kconfig | 14 + drivers/staging/media/ipu3/Makefile| 11 + drivers/staging/media/ipu3/TODO| 23 + drivers/staging/media/ipu3/include/intel-ipu3.h| 2785 ++ drivers/staging/media/ipu3/ipu3-abi.h | 2011 drivers/staging/media/ipu3/ipu3-css-fw.c | 265 + drivers/staging/media/ipu3/ipu3-css-fw.h | 188 + drivers/staging/media/ipu3/ipu3-css-params.c | 2943 ++ drivers/staging/media/ipu3/ipu3-css-params.h | 28 + drivers/staging/media/ipu3/ipu3-css-pool.c | 100 + drivers/staging/media/ipu3/ipu3-css-pool.h | 55 + drivers/staging/media/ipu3/ipu3-css.c | 2391 + drivers/staging/media/ipu3/ipu3-css.h | 213 + drivers/staging/media/ipu3/ipu3-dmamap.c | 270 + drivers/staging/media/ipu3/ipu3-dmamap.h | 22 + drivers/staging/media/ipu3/ipu3-mmu.c | 561 ++ drivers/staging/media/ipu3/ipu3-mmu.h | 35 + drivers/staging/media/ipu3/ipu3-tables.c | 9609 drivers/staging/media/ipu3/ipu3-tables.h | 66 + drivers/staging/media/ipu3/ipu3-v4l2.c | 1419 +++ drivers/staging/media/ipu3/ipu3.c | 830 ++ drivers/staging/media/ipu3/ipu3.h | 168 + include/uapi/linux/v4l2-controls.h |4 + include/uapi/linux/videodev2.h |4 + 31 files changed, 24526 insertions(+) create mode 100644 Documentation/media/uapi/v4l/pixfmt-meta-intel-ipu3.rst create mode 100644 Documentation/media/v4l-drivers/ipu3.rst create mode 100644 drivers/staging/media/ipu3/Kconfig create mode 100644 drivers/staging/media/ipu3/Makefile create mode 100644 drivers/staging/media/ipu3/TODO create mode 100644 drivers/staging/media/ipu3/include/intel-ipu3.h create mode 100644 drivers/staging/media/ipu3/ipu3-abi.h create mode 100644 drivers/staging/media/
[PATCH v8 11/17] media: staging/intel-ipu3: Add v4l2 driver based on media framework
Implement video driver that utilizes v4l2, vb2 queue support and media controller APIs. The driver exposes single subdevice and six nodes. Signed-off-by: Yong Zhi --- drivers/staging/media/ipu3/ipu3-v4l2.c | 1086 1 file changed, 1086 insertions(+) create mode 100644 drivers/staging/media/ipu3/ipu3-v4l2.c diff --git a/drivers/staging/media/ipu3/ipu3-v4l2.c b/drivers/staging/media/ipu3/ipu3-v4l2.c new file mode 100644 index ..038ee749cb75 --- /dev/null +++ b/drivers/staging/media/ipu3/ipu3-v4l2.c @@ -0,0 +1,1086 @@ +// SPDX-License-Identifier: GPL-2.0 +// Copyright (C) 2018 Intel Corporation + +#include +#include + +#include + +#include "ipu3.h" +#include "ipu3-dmamap.h" + +/ v4l2_subdev_ops / + +static int ipu3_subdev_open(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh) +{ + struct v4l2_rect try_crop = { + .top = 0, + .left = 0, + .width = 1920, + .height = 1080, + }; + unsigned int i; + + /* Initialize try_fmt */ + for (i = 0; i < IMGU_NODE_NUM; i++) { + struct v4l2_mbus_framefmt *try_fmt = + v4l2_subdev_get_try_format(sd, fh->pad, i); + + try_fmt->width = try_crop.width; + try_fmt->height = try_crop.height; + try_fmt->code = MEDIA_BUS_FMT_FIXED; + try_fmt->colorspace = V4L2_COLORSPACE_RAW; + try_fmt->field = V4L2_FIELD_NONE; + } + + *v4l2_subdev_get_try_crop(sd, fh->pad, IMGU_NODE_IN) = try_crop; + *v4l2_subdev_get_try_compose(sd, fh->pad, IMGU_NODE_IN) = try_crop; + + return 0; +} + +static int ipu3_subdev_s_stream(struct v4l2_subdev *sd, int enable) +{ + struct imgu_device *imgu = container_of(sd, struct imgu_device, subdev); + int r = 0; + + r = imgu_s_stream(imgu, enable); + if (!r) + imgu->streaming = enable; + + return r; +} + +static int ipu3_subdev_get_fmt(struct v4l2_subdev *sd, + struct v4l2_subdev_pad_config *cfg, + struct v4l2_subdev_format *fmt) +{ + struct imgu_device *imgu = container_of(sd, struct imgu_device, subdev); + struct v4l2_mbus_framefmt *mf; + u32 pad = fmt->pad; + + if (fmt->which == V4L2_SUBDEV_FORMAT_ACTIVE) { + fmt->format = imgu->nodes[pad].pad_fmt; + } else { + mf = v4l2_subdev_get_try_format(sd, cfg, pad); + fmt->format = *mf; + } + + return 0; +} + +static int ipu3_subdev_set_fmt(struct v4l2_subdev *sd, + struct v4l2_subdev_pad_config *cfg, + struct v4l2_subdev_format *fmt) +{ + struct imgu_device *imgu = container_of(sd, struct imgu_device, subdev); + struct v4l2_mbus_framefmt *mf; + u32 pad = fmt->pad; + + if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) + mf = v4l2_subdev_get_try_format(sd, cfg, pad); + else + mf = &imgu->nodes[pad].pad_fmt; + + fmt->format.code = mf->code; + /* Clamp the w and h based on the hardware capabilities */ + if (imgu->subdev_pads[pad].flags & MEDIA_PAD_FL_SOURCE) { + fmt->format.width = clamp(fmt->format.width, + IPU3_OUTPUT_MIN_WIDTH, + IPU3_OUTPUT_MAX_WIDTH); + fmt->format.height = clamp(fmt->format.height, + IPU3_OUTPUT_MIN_HEIGHT, + IPU3_OUTPUT_MAX_HEIGHT); + } else { + fmt->format.width = clamp(fmt->format.width, + IPU3_INPUT_MIN_WIDTH, + IPU3_INPUT_MAX_WIDTH); + fmt->format.height = clamp(fmt->format.height, + IPU3_INPUT_MIN_HEIGHT, + IPU3_INPUT_MAX_HEIGHT); + } + + *mf = fmt->format; + + return 0; +} + +static int ipu3_subdev_get_selection(struct v4l2_subdev *sd, +struct v4l2_subdev_pad_config *cfg, +struct v4l2_subdev_selection *sel) +{ + struct imgu_device *imgu = container_of(sd, struct imgu_device, subdev); + struct v4l2_rect *try_sel, *r; + + if (sel->pad != IMGU_NODE_IN) + return -EINVAL; + + switch (sel->target) { + case V4L2_SEL_TGT_CROP: + try_sel = v4l2_subdev_get_try_crop(sd, cfg, sel->pad); + r = &imgu->rect.eff; + break; + case V4L2_SEL_TGT_COMPOSE: + try_sel = v4l2_subdev_get_try_c
[PATCH v8 13/17] media: staging/intel-ipu3: Add Intel IPU3 meta data uAPI
These meta formats are used on Intel IPU3 ImgU video queues to carry 3A statistics and ISP pipeline parameters. V4L2_META_FMT_IPU3_3A V4L2_META_FMT_IPU3_PARAMS Signed-off-by: Yong Zhi Signed-off-by: Chao C Li Signed-off-by: Rajmohan Mani --- drivers/staging/media/ipu3/include/intel-ipu3.h | 2775 +++ 1 file changed, 2775 insertions(+) create mode 100644 drivers/staging/media/ipu3/include/intel-ipu3.h diff --git a/drivers/staging/media/ipu3/include/intel-ipu3.h b/drivers/staging/media/ipu3/include/intel-ipu3.h new file mode 100644 index ..07fd66817358 --- /dev/null +++ b/drivers/staging/media/ipu3/include/intel-ipu3.h @@ -0,0 +1,2775 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* Copyright (C) 2017 - 2018 Intel Corporation */ + +#ifndef __IPU3_UAPI_H +#define __IPU3_UAPI_H + +#include + +/* from /drivers/staging/media/ipu3/include/videodev2.h */ + +/* Vendor specific - used for IPU3 camera sub-system */ +#define V4L2_META_FMT_IPU3_PARAMS v4l2_fourcc('i', 'p', '3', 'p') /* IPU3 processing parameters */ +#define V4L2_META_FMT_IPU3_STAT_3A v4l2_fourcc('i', 'p', '3', 's') /* IPU3 3A statistics */ + +/*** ipu3_uapi_stats_3a ***/ + +#define IPU3_UAPI_MAX_STRIPES 2 +#define IPU3_UAPI_MAX_BUBBLE_SIZE 10 + +#define IPU3_UAPI_GRID_START_MASK ((1 << 12) - 1) +#define IPU3_UAPI_GRID_Y_START_EN (1 << 15) + +/* controls generation of meta_data (like FF enable/disable) */ +#define IPU3_UAPI_AWB_RGBS_THR_B_EN(1 << 14) +#define IPU3_UAPI_AWB_RGBS_THR_B_INCL_SAT (1 << 15) + +/** + * struct ipu3_uapi_grid_config - Grid plane config + * + * @width: Grid horizontal dimensions, in number of grid blocks(cells). + * @height:Grid vertical dimensions, in number of grid cells. + * @block_width_log2: Log2 of the width of each cell in pixels. + * for (2^3, 2^4, 2^5, 2^6, 2^7), values [3, 7]. + * @block_height_log2: Log2 of the height of each cell in pixels. + * for (2^3, 2^4, 2^5, 2^6, 2^7), values [3, 7]. + * @height_per_slice: The number of blocks in vertical axis per slice. + * Default 2. + * @x_start: X value of top left corner of Region of Interest(ROI). + * @y_start: Y value of top left corner of ROI + * @x_end: X value of bottom right corner of ROI + * @y_end: Y value of bottom right corner of ROI + * + * Due to the size of total amount of collected data, most statistics + * create a grid-based output, and the data is then divided into "slices". + */ +struct ipu3_uapi_grid_config { + __u8 width; + __u8 height; + __u16 block_width_log2:3; + __u16 block_height_log2:3; + __u16 height_per_slice:8; + __u16 x_start; + __u16 y_start; + __u16 x_end; + __u16 y_end; +} __packed; + +/* + * The grid based data is divided into "slices" called set, each slice of setX + * refers to ipu3_uapi_grid_config width * height_per_slice. + */ +#define IPU3_UAPI_AWB_MAX_SETS 60 +/* Based on grid size 80 * 60 and cell size 16 x 16 */ +#define IPU3_UAPI_AWB_SET_SIZE 1280 +#define IPU3_UAPI_AWB_MD_ITEM_SIZE 8 +#define IPU3_UAPI_AWB_SPARE_FOR_BUBBLES \ + (IPU3_UAPI_MAX_BUBBLE_SIZE * IPU3_UAPI_MAX_STRIPES * \ +IPU3_UAPI_AWB_MD_ITEM_SIZE) +#define IPU3_UAPI_AWB_MAX_BUFFER_SIZE \ + (IPU3_UAPI_AWB_MAX_SETS * \ +(IPU3_UAPI_AWB_SET_SIZE + IPU3_UAPI_AWB_SPARE_FOR_BUBBLES)) + + +/** + * struct ipu3_uapi_awb_raw_buffer - AWB raw buffer + * + * @meta_data: buffer to hold auto white balance meta data which is + * the average values for each color channel. + */ +struct ipu3_uapi_awb_raw_buffer { + __u8 meta_data[IPU3_UAPI_AWB_MAX_BUFFER_SIZE] + __attribute__((aligned(32))); +} __packed; + +/** + * struct ipu3_uapi_awb_config_s - AWB config + * + * @rgbs_thr_gr: gr threshold value. + * @rgbs_thr_r: Red threshold value. + * @rgbs_thr_gb: gb threshold value. + * @rgbs_thr_b: Blue threshold value. + * @grid: &ipu3_uapi_grid_config, the default grid resolution is 16x16 cells. + * + * The threshold is a saturation measure range [0, 8191], 8191 is default. + * Values over threshold may be optionally rejected for averaging. + */ +struct ipu3_uapi_awb_config_s { + __u16 rgbs_thr_gr; + __u16 rgbs_thr_r; + __u16 rgbs_thr_gb; + __u16 rgbs_thr_b; + struct ipu3_uapi_grid_config grid; +} __attribute__((aligned(32))) __packed; + +/** + * struct ipu3_uapi_awb_config - AWB config wrapper + * + * @config: config for auto white balance as defined by &ipu3_uapi_awb_config_s + */ +struct ipu3_uapi_awb_config { + struct ipu3_uapi_awb_config_s config __attribute__((align
[PATCH v8 05/17] media: staging/intel-ipu3: css: Add dma buff pool utility functions
The pools are used to store previous parameters set by user with the parameter queue. Due to pipelining, there needs to be multiple sets (up to four) of parameters which are queued in a host-to-sp queue. Signed-off-by: Yong Zhi --- drivers/staging/media/ipu3/ipu3-css-pool.c | 100 + drivers/staging/media/ipu3/ipu3-css-pool.h | 55 2 files changed, 155 insertions(+) create mode 100644 drivers/staging/media/ipu3/ipu3-css-pool.c create mode 100644 drivers/staging/media/ipu3/ipu3-css-pool.h diff --git a/drivers/staging/media/ipu3/ipu3-css-pool.c b/drivers/staging/media/ipu3/ipu3-css-pool.c new file mode 100644 index ..6f271f81669b --- /dev/null +++ b/drivers/staging/media/ipu3/ipu3-css-pool.c @@ -0,0 +1,100 @@ +// SPDX-License-Identifier: GPL-2.0 +// Copyright (C) 2018 Intel Corporation + +#include + +#include "ipu3.h" +#include "ipu3-css-pool.h" +#include "ipu3-dmamap.h" + +int ipu3_css_dma_buffer_resize(struct imgu_device *imgu, + struct ipu3_css_map *map, size_t size) +{ + if (map->size < size && map->vaddr) { + dev_warn(&imgu->pci_dev->dev, "dma buf resized from %zu to %zu", +map->size, size); + + ipu3_dmamap_free(imgu, map); + if (!ipu3_dmamap_alloc(imgu, map, size)) + return -ENOMEM; + } + + return 0; +} + +void ipu3_css_pool_cleanup(struct imgu_device *imgu, struct ipu3_css_pool *pool) +{ + unsigned int i; + + for (i = 0; i < IPU3_CSS_POOL_SIZE; i++) + ipu3_dmamap_free(imgu, &pool->entry[i].param); +} + +int ipu3_css_pool_init(struct imgu_device *imgu, struct ipu3_css_pool *pool, + size_t size) +{ + unsigned int i; + + for (i = 0; i < IPU3_CSS_POOL_SIZE; i++) { + pool->entry[i].valid = false; + if (size == 0) { + pool->entry[i].param.vaddr = NULL; + continue; + } + + if (!ipu3_dmamap_alloc(imgu, &pool->entry[i].param, size)) + goto fail; + } + + pool->last = IPU3_CSS_POOL_SIZE; + + return 0; + +fail: + ipu3_css_pool_cleanup(imgu, pool); + return -ENOMEM; +} + +/* + * Allocate a new parameter via recycling the oldest entry in the pool. + */ +void ipu3_css_pool_get(struct ipu3_css_pool *pool) +{ + /* Get the oldest entry */ + u32 n = (pool->last + 1) % IPU3_CSS_POOL_SIZE; + + pool->entry[n].valid = true; + pool->last = n; +} + +/* + * Undo, for all practical purposes, the effect of pool_get(). + */ +void ipu3_css_pool_put(struct ipu3_css_pool *pool) +{ + pool->entry[pool->last].valid = false; + pool->last = (pool->last + IPU3_CSS_POOL_SIZE - 1) % IPU3_CSS_POOL_SIZE; +} + +/** + * ipu3_css_pool_last - Retrieve the nth pool entry from last + * + * @pool: a pointer to &struct ipu3_css_pool. + * @n: the distance to the last index. + * + * Returns: + * The nth entry from last or null map to indicate no frame stored. + */ +const struct ipu3_css_map * +ipu3_css_pool_last(struct ipu3_css_pool *pool, unsigned int n) +{ + static const struct ipu3_css_map null_map = { 0 }; + int i = (pool->last + IPU3_CSS_POOL_SIZE - n) % IPU3_CSS_POOL_SIZE; + + WARN_ON(n >= IPU3_CSS_POOL_SIZE); + + if (!pool->entry[i].valid) + return &null_map; + + return &pool->entry[i].param; +} diff --git a/drivers/staging/media/ipu3/ipu3-css-pool.h b/drivers/staging/media/ipu3/ipu3-css-pool.h new file mode 100644 index ..9c895efd2bfa --- /dev/null +++ b/drivers/staging/media/ipu3/ipu3-css-pool.h @@ -0,0 +1,55 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* Copyright (C) 2018 Intel Corporation */ + +#ifndef __IPU3_UTIL_H +#define __IPU3_UTIL_H + +struct device; +struct imgu_device; + +#define IPU3_CSS_POOL_SIZE 4 + +/** + * ipu3_css_map - store DMA mapping info for buffer + * + * @size: size of the buffer in bytes. + * @vaddr: kernel virtual address. + * @daddr: iova dma address to access IPU3. + * @vma: private, a pointer to &struct vm_struct, + * used for ipu3_dmamap_free. + */ +struct ipu3_css_map { + size_t size; + void *vaddr; + dma_addr_t daddr; + struct vm_struct *vma; +}; + +/** + * ipu3_css_pool - circular buffer pool definition + * + * @entry: array with IPU3_CSS_POOL_SIZE elements. + * @entry.param: a &struct ipu3_css_map for storing the mem mapping. + * @entry.valid: used to mark if the entry has vaid data. + * @last: write pointer, initialized to IPU3_CSS_POOL_SIZE. + */ +struct ipu3_css_pool { + struct { + struct ipu3_cs
[PATCH v8 04/17] media: staging/intel-ipu3: Implement DMA mapping functions
From: Tomasz Figa This driver uses IOVA space for buffer mapping through IPU3 MMU to transfer data between imaging pipelines and system DDR. Signed-off-by: Tomasz Figa Signed-off-by: Yong Zhi --- drivers/staging/media/ipu3/ipu3-dmamap.c | 270 +++ drivers/staging/media/ipu3/ipu3-dmamap.h | 22 +++ 2 files changed, 292 insertions(+) create mode 100644 drivers/staging/media/ipu3/ipu3-dmamap.c create mode 100644 drivers/staging/media/ipu3/ipu3-dmamap.h diff --git a/drivers/staging/media/ipu3/ipu3-dmamap.c b/drivers/staging/media/ipu3/ipu3-dmamap.c new file mode 100644 index ..93a393d4e15e --- /dev/null +++ b/drivers/staging/media/ipu3/ipu3-dmamap.c @@ -0,0 +1,270 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (C) 2018 Intel Corporation + * Copyright 2018 Google LLC. + * + * Author: Tomasz Figa + * Author: Yong Zhi + */ + +#include + +#include "ipu3.h" +#include "ipu3-css-pool.h" +#include "ipu3-mmu.h" + +/* + * Free a buffer allocated by ipu3_dmamap_alloc_buffer() + */ +static void ipu3_dmamap_free_buffer(struct page **pages, + size_t size) +{ + int count = size >> PAGE_SHIFT; + + while (count--) + __free_page(pages[count]); + kvfree(pages); +} + +/* + * Based on the implementation of __iommu_dma_alloc_pages() + * defined in drivers/iommu/dma-iommu.c + */ +static struct page **ipu3_dmamap_alloc_buffer(size_t size, + unsigned long order_mask, + gfp_t gfp) +{ + struct page **pages; + unsigned int i = 0, count = size >> PAGE_SHIFT; + const gfp_t high_order_gfp = __GFP_NOWARN | __GFP_NORETRY; + + /* Allocate mem for array of page ptrs */ + pages = kvmalloc_array(count, sizeof(*pages), GFP_KERNEL); + + if (!pages) + return NULL; + + order_mask &= (2U << MAX_ORDER) - 1; + if (!order_mask) + return NULL; + + gfp |= __GFP_HIGHMEM | __GFP_ZERO; + + while (count) { + struct page *page = NULL; + unsigned int order_size; + + for (order_mask &= (2U << __fls(count)) - 1; +order_mask; order_mask &= ~order_size) { + unsigned int order = __fls(order_mask); + + order_size = 1U << order; + page = alloc_pages((order_mask - order_size) ? + gfp | high_order_gfp : gfp, order); + if (!page) + continue; + if (!order) + break; + if (!PageCompound(page)) { + split_page(page, order); + break; + } + + __free_pages(page, order); + } + if (!page) { + ipu3_dmamap_free_buffer(pages, i << PAGE_SHIFT); + return NULL; + } + count -= order_size; + while (order_size--) + pages[i++] = page++; + } + + return pages; +} + +/** + * ipu3_dmamap_alloc - allocate and map a buffer into KVA + * @imgu: struct device pointer + * @map: struct to store mapping variables + * @len: size required + * + * Returns: + * KVA on success + * %NULL on failure + */ +void *ipu3_dmamap_alloc(struct imgu_device *imgu, struct ipu3_css_map *map, + size_t len) +{ + unsigned long shift = iova_shift(&imgu->iova_domain); + unsigned int alloc_sizes = imgu->mmu->pgsize_bitmap; + struct device *dev = &imgu->pci_dev->dev; + size_t size = PAGE_ALIGN(len); + struct page **pages; + dma_addr_t iovaddr; + struct iova *iova; + int i, rval; + + dev_dbg(dev, "%s: allocating %zu\n", __func__, size); + + iova = alloc_iova(&imgu->iova_domain, size >> shift, + imgu->mmu->aperture_end >> shift, 0); + if (!iova) + return NULL; + + pages = ipu3_dmamap_alloc_buffer(size, alloc_sizes >> PAGE_SHIFT, +GFP_KERNEL); + if (!pages) + goto out_free_iova; + + /* Call IOMMU driver to setup pgt */ + iovaddr = iova_dma_addr(&imgu->iova_domain, iova); + for (i = 0; i < size / PAGE_SIZE; ++i) { + rval = ipu3_mmu_map(imgu->mmu, iovaddr, + page_to_phys(pages[i]), PAGE_SIZE); + if (rval) + goto out_unmap; + + iovaddr += PAGE_SIZE; + } + + /* Now grab a virtual region */ + map->vma = __get_vm_area(siz
[PATCH v8 02/17] media: staging/intel-ipu3: abi: Add structs
This add all the structs of IPU3 firmware ABI. Signed-off-by: Yong Zhi Signed-off-by: Rajmohan Mani Reviewed-by: Laurent Pinchart --- drivers/staging/media/ipu3/ipu3-abi.h | 1350 + 1 file changed, 1350 insertions(+) diff --git a/drivers/staging/media/ipu3/ipu3-abi.h b/drivers/staging/media/ipu3/ipu3-abi.h index e754ff5836c2..25be56ff01c8 100644 --- a/drivers/staging/media/ipu3/ipu3-abi.h +++ b/drivers/staging/media/ipu3/ipu3-abi.h @@ -658,4 +658,1354 @@ enum imgu_abi_stage_type { IMGU_ABI_STAGE_TYPE_ISP, }; +struct imgu_abi_acc_operation { + /* +* zero means on init, +* others mean upon receiving an ack signal from the BC acc. +*/ + u8 op_indicator; + u8 op_type; +} __packed; + +struct imgu_abi_acc_process_lines_cmd_data { + u16 lines; + u8 cfg_set; + u8 reserved;/* Align to 4 bytes */ +} __packed; + +/* Bayer shading definitions */ + +struct imgu_abi_shd_transfer_luts_set_data { + u8 set_number; + u8 padding[3]; + imgu_addr_t rg_lut_ddr_addr; + imgu_addr_t bg_lut_ddr_addr; + u32 align_dummy; +} __packed; + +struct imgu_abi_shd_grid_config { + /* reg 0 */ + u32 grid_width:8; + u32 grid_height:8; + u32 block_width:3; + u32 reserved0:1; + u32 block_height:3; + u32 reserved1:1; + u32 grid_height_per_slice:8; + /* reg 1 */ + s32 x_start:13; + s32 reserved2:3; + s32 y_start:13; + s32 reserved3:3; +} __packed; + +struct imgu_abi_shd_general_config { + u32 init_set_vrt_offst_ul:8; + u32 shd_enable:1; + /* aka 'gf' */ + u32 gain_factor:2; + u32 reserved:21; +} __packed; + +struct imgu_abi_shd_black_level_config { + /* reg 0 */ + s32 bl_r:12; + s32 reserved0:4; + s32 bl_gr:12; + u32 reserved1:1; + /* aka 'nf' */ + u32 normalization_shift:3; + /* reg 1 */ + s32 bl_gb:12; + s32 reserved2:4; + s32 bl_b:12; + s32 reserved3:4; +} __packed; + +struct imgu_abi_shd_intra_frame_operations_data { + struct imgu_abi_acc_operation + operation_list[IMGU_ABI_SHD_MAX_OPERATIONS] __aligned(32); + struct imgu_abi_acc_process_lines_cmd_data + process_lines_data[IMGU_ABI_SHD_MAX_PROCESS_LINES] __aligned(32); + struct imgu_abi_shd_transfer_luts_set_data + transfer_data[IMGU_ABI_SHD_MAX_TRANSFERS] __aligned(32); +} __packed; + +struct imgu_abi_shd_config { + struct ipu3_uapi_shd_config_static shd __aligned(32); + struct imgu_abi_shd_intra_frame_operations_data shd_ops __aligned(32); + struct ipu3_uapi_shd_lut shd_lut __aligned(32); +} __packed; + +struct imgu_abi_stripe_input_frame_resolution { + u16 width; + u16 height; + u32 bayer_order;/* enum ipu3_uapi_bayer_order */ + u32 raw_bit_depth; +} __packed; + +/* Stripe-based processing */ + +struct imgu_abi_stripes { + /* offset from start of frame - measured in pixels */ + u16 offset; + /* stripe width - measured in pixels */ + u16 width; + /* stripe width - measured in pixels */ + u16 height; +} __packed; + +struct imgu_abi_stripe_data { + /* +* number of stripes for current processing source +* - VLIW binary parameter we currently support 1 or 2 stripes +*/ + u16 num_of_stripes; + + u8 padding[2]; + + /* +* the following data is derived from resolution-related +* pipe config and from num_of_stripes +*/ + + /* +*'input-stripes' - before input cropping +* used by input feeder +*/ + struct imgu_abi_stripe_input_frame_resolution input_frame; + + /*'effective-stripes' - after input cropping used dpc, bds */ + struct imgu_abi_stripes effective_stripes[IPU3_UAPI_MAX_STRIPES]; + + /* 'down-scaled-stripes' - after down-scaling ONLY. used by BDS */ + struct imgu_abi_stripes down_scaled_stripes[IPU3_UAPI_MAX_STRIPES]; + + /* +*'bds-out-stripes' - after bayer down-scaling and padding. +* used by all algos starting with norm up to the ref-frame for GDC +* (currently up to the output kernel) +*/ + struct imgu_abi_stripes bds_out_stripes[IPU3_UAPI_MAX_STRIPES]; + + /* 'bds-out-stripes (no overlap)' - used for ref kernel */ + struct imgu_abi_stripes + bds_out_stripes_no_overlap[IPU3_UAPI_MAX_STRIPES]; + + /* +* input resolution for output system (equal to bds_out - envelope) +* output-system input frame width as configured by user +*/ + u16 output_system_in_frame_width; + /* output-system input frame height as configured by user */ + u16 output_system_in_frame_height; + + /* +
[PATCH v8 03/17] media: staging/intel-ipu3: mmu: Implement driver
From: Tomasz Figa This driver translates IO virtual address to physical address based on two levels page tables. Signed-off-by: Tomasz Figa Signed-off-by: Yong Zhi --- drivers/staging/media/ipu3/ipu3-mmu.c | 561 ++ drivers/staging/media/ipu3/ipu3-mmu.h | 35 +++ 2 files changed, 596 insertions(+) create mode 100644 drivers/staging/media/ipu3/ipu3-mmu.c create mode 100644 drivers/staging/media/ipu3/ipu3-mmu.h diff --git a/drivers/staging/media/ipu3/ipu3-mmu.c b/drivers/staging/media/ipu3/ipu3-mmu.c new file mode 100644 index ..b9f209541f78 --- /dev/null +++ b/drivers/staging/media/ipu3/ipu3-mmu.c @@ -0,0 +1,561 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (C) 2018 Intel Corporation. + * Copyright 2018 Google LLC. + * + * Author: Tuukka Toivonen + * Author: Sakari Ailus + * Author: Samu Onkalo + * Author: Tomasz Figa + * + */ + +#include +#include +#include +#include +#include + +#include + +#include "ipu3-mmu.h" + +#define IPU3_PAGE_SHIFT12 +#define IPU3_PAGE_SIZE (1UL << IPU3_PAGE_SHIFT) + +#define IPU3_PT_BITS 10 +#define IPU3_PT_PTES (1UL << IPU3_PT_BITS) +#define IPU3_PT_SIZE (IPU3_PT_PTES << 2) +#define IPU3_PT_ORDER (IPU3_PT_SIZE >> PAGE_SHIFT) + +#define IPU3_ADDR2PTE(addr)((addr) >> IPU3_PAGE_SHIFT) +#define IPU3_PTE2ADDR(pte) ((phys_addr_t)(pte) << IPU3_PAGE_SHIFT) + +#define IPU3_L2PT_SHIFTIPU3_PT_BITS +#define IPU3_L2PT_MASK ((1UL << IPU3_L2PT_SHIFT) - 1) + +#define IPU3_L1PT_SHIFTIPU3_PT_BITS +#define IPU3_L1PT_MASK ((1UL << IPU3_L1PT_SHIFT) - 1) + +#define IPU3_MMU_ADDRESS_BITS (IPU3_PAGE_SHIFT + \ +IPU3_L2PT_SHIFT + \ +IPU3_L1PT_SHIFT) + +#define IMGU_REG_BASE 0x4000 +#define REG_TLB_INVALIDATE (IMGU_REG_BASE + 0x300) +#define TLB_INVALIDATE 1 +#define REG_L1_PHYS(IMGU_REG_BASE + 0x304) /* 27-bit pfn */ +#define REG_GP_HALT(IMGU_REG_BASE + 0x5dc) +#define REG_GP_HALTED (IMGU_REG_BASE + 0x5e0) + +struct ipu3_mmu { + struct device *dev; + void __iomem *base; + /* protect access to l2pts, l1pt */ + spinlock_t lock; + + void *dummy_page; + u32 dummy_page_pteval; + + u32 *dummy_l2pt; + u32 dummy_l2pt_pteval; + + u32 **l2pts; + u32 *l1pt; + + struct ipu3_mmu_info geometry; +}; + +static inline struct ipu3_mmu *to_ipu3_mmu(struct ipu3_mmu_info *info) +{ + return container_of(info, struct ipu3_mmu, geometry); +} + +/** + * ipu3_mmu_tlb_invalidate - invalidate translation look-aside buffer + * @mmu: MMU to perform the invalidate operation on + * + * This function invalidates the whole TLB. Must be called when the hardware + * is powered on. + */ +static void ipu3_mmu_tlb_invalidate(struct ipu3_mmu *mmu) +{ + writel(TLB_INVALIDATE, mmu->base + REG_TLB_INVALIDATE); +} + +static void call_if_ipu3_is_powered(struct ipu3_mmu *mmu, + void (*func)(struct ipu3_mmu *mmu)) +{ + if (!pm_runtime_get_if_in_use(mmu->dev)) + return; + + func(mmu); + pm_runtime_put(mmu->dev); +} + +/** + * ipu3_mmu_set_halt - set CIO gate halt bit + * @mmu: MMU to set the CIO gate bit in. + * @halt: Desired state of the gate bit. + * + * This function sets the CIO gate bit that controls whether external memory + * accesses are allowed. Must be called when the hardware is powered on. + */ +static void ipu3_mmu_set_halt(struct ipu3_mmu *mmu, bool halt) +{ + int ret; + u32 val; + + writel(halt, mmu->base + REG_GP_HALT); + ret = readl_poll_timeout(mmu->base + REG_GP_HALTED, +val, (val & 1) == halt, 1000, 10); + + if (ret) + dev_err(mmu->dev, "failed to %s CIO gate halt\n", + halt ? "set" : "clear"); +} + +/** + * ipu3_mmu_alloc_page_table - allocate a pre-filled page table + * @pteval: Value to initialize for page table entries with. + * + * Return: Pointer to allocated page table or NULL on failure. + */ +static u32 *ipu3_mmu_alloc_page_table(u32 pteval) +{ + u32 *pt; + int pte; + + pt = (u32 *)__get_free_page(GFP_KERNEL); + if (!pt) + return NULL; + + for (pte = 0; pte < IPU3_PT_PTES; pte++) + pt[pte] = pteval; + + set_memory_uc((unsigned long int)pt, IPU3_PT_ORDER); + + return pt; +} + +/** + * ipu3_mmu_free_page_table - free page table + * @pt: Page table to free. + */ +static void ipu3_mmu_free_page_table(u32 *pt) +{ + set_memory_wb((unsigned long int)pt, IPU3_PT_ORDER); + free_page((unsigned long)pt); +} + +/** + * address_to_pte_idx - split IOVA into L1 and L2 page table indices + * @io
[PATCH v8 17/17] doc-rst: Add Intel IPU3 documentation
From: Rajmohan Mani This patch adds the details about the IPU3 Imaging Unit driver. Change-Id: I560cecf673df2dcc3ec72767cf8077708d649656 Signed-off-by: Rajmohan Mani --- Documentation/media/v4l-drivers/index.rst | 1 + Documentation/media/v4l-drivers/ipu3.rst | 326 ++ 2 files changed, 327 insertions(+) create mode 100644 Documentation/media/v4l-drivers/ipu3.rst diff --git a/Documentation/media/v4l-drivers/index.rst b/Documentation/media/v4l-drivers/index.rst index 6cdd3bc98202..f28570ec9e42 100644 --- a/Documentation/media/v4l-drivers/index.rst +++ b/Documentation/media/v4l-drivers/index.rst @@ -44,6 +44,7 @@ For more details see the file COPYING in the source distribution of Linux. davinci-vpbe fimc imx + ipu3 ivtv max2175 meye diff --git a/Documentation/media/v4l-drivers/ipu3.rst b/Documentation/media/v4l-drivers/ipu3.rst new file mode 100644 index ..045bf4222b1a --- /dev/null +++ b/Documentation/media/v4l-drivers/ipu3.rst @@ -0,0 +1,326 @@ +.. include:: + +=== +Intel Image Processing Unit 3 (IPU3) Imaging Unit (ImgU) driver +=== + +Copyright |copy| 2018 Intel Corporation + +Introduction + + +This file documents Intel IPU3 (3rd generation Image Processing Unit) Imaging +Unit driver located under drivers/media/pci/intel/ipu3. + +The Intel IPU3 found in certain Kaby Lake (as well as certain Sky Lake) +platforms (U/Y processor lines) is made up of two parts namely Imaging Unit +(ImgU) and CIO2 device (MIPI CSI2 receiver). + +The CIO2 device receives the raw bayer data from the sensors and outputs the +frames in a format that is specific to IPU3 (for consumption by IPU3 ImgU). +CIO2 driver is available as drivers/media/pci/intel/ipu3/ipu3-cio2* and is +enabled through the CONFIG_VIDEO_IPU3_CIO2 config option. + +The Imaging Unit (ImgU) is responsible for processing images captured +through IPU3 CIO2 device. The ImgU driver sources can be found under +drivers/media/pci/intel/ipu3 directory. The driver is enabled through the +CONFIG_VIDEO_IPU3_IMGU config option. + +The two driver modules are named ipu3-csi2 and ipu3-imgu, respectively. + +The driver has been tested on Kaby Lake platforms (U/Y processor lines). + +The driver implements V4L2, Media controller and V4L2 sub-device interfaces. +Camera sensors that have CSI-2 bus, which are connected to the IPU3 CIO2 +device are supported. Support for lens and flash drivers depends on the +above sensors. + +ImgU device nodes += + +The ImgU is represented as two V4L2 subdevs, each of which provides a V4L2 +subdev interface to the user space. + +Each V4L2 subdev represents a pipe, which can support a maximum of 2 +streams. A private ioctl can be used to configure the mode (video or still) +of the pipe. + +This helps to support advanced camera features like Continuous View Finder +(CVF) and Snapshot During Video(SDV). + +CIO2 device +=== + +The CIO2 is represented as a single V4L2 subdev, which provides a V4L2 subdev +interface to the user space. There is a video node for each CSI-2 receiver, +with a single media controller interface for the entire device. + +Media controller + + +The media device interface allows to configure the ImgU links, which defines +the behavior of the IPU3 firmware. + +Device operation + + +With IPU3, once the input video node ("ipu3-imgu 0/1":0, +in : format) is queued with buffer (in packed raw bayer +format), IPU3 ISP starts processing the buffer and produces the video output +in YUV format and statistics output on respective output nodes. The driver +is expected to have buffers ready for all of parameter, output and +statistics nodes, when input video node is queued with buffer. + +At a minimum, all of input, main output, 3A statistics and viewfinder +video nodes should be enabled for IPU3 to start image processing. + +Each ImgU V4L2 subdev has the following set of video nodes. + +input, output and viewfinder video nodes + + +The frames (in packed raw bayer format specific to IPU3) received by the +input video node is processed by the IPU3 Imaging Unit and is output to 2 +video nodes, with each targeting different purpose (main output and viewfinder +output). + +Details on raw bayer format specific to IPU3 can be found as below. +Documentation/media/uapi/v4l/pixfmt-meta-intel-ipu3.rst + +The driver supports V4L2 Video Capture Interface as defined at :ref:`devices`. + +Only the multi-planar API is supported. More details can be found at +:ref:`planar-apis`. + + +parameters video node +- + +The parameter video node receives the ISP algorithm parameters that are used +to configure how the ISP algorithms process the image. + +Details on raw bayer format specific to IPU3 can be found as below.
[PATCH v8 16/17] media: v4l2-ctrls: Reserve controls for IPU3 ImgU
From: "Cao,Bing Bu" Add a base to be used for allocation of all the IPU3 specific controls in the ImgU driver. Signed-off-by: Yong Zhi Signed-off-by: Tian Shu Qiu --- include/uapi/linux/v4l2-controls.h | 4 1 file changed, 4 insertions(+) diff --git a/include/uapi/linux/v4l2-controls.h b/include/uapi/linux/v4l2-controls.h index 998983a6e6b7..2b52f44d0ba5 100644 --- a/include/uapi/linux/v4l2-controls.h +++ b/include/uapi/linux/v4l2-controls.h @@ -192,6 +192,10 @@ enum v4l2_colorfx { * We reserve 16 controls for this driver. */ #define V4L2_CID_USER_IMX_BASE (V4L2_CID_USER_BASE + 0x10b0) +/* The base for the ipu3 ImgU driver controls. + * We reserve 16 controls for this driver. */ +#define V4L2_CID_INTEL_IPU3_BASE (V4L2_CID_USER_BASE + 0x10c0) + /* MPEG-class control IDs */ /* The MPEG controls are applicable to all codec controls * and the 'MPEG' part of the define is historical */ -- 2.7.4
RE: [PATCH v7 01/16] v4l: Add Intel IPU3 meta buffer formats
Hi, Laurent, Thanks for the review. > -Original Message- > From: Laurent Pinchart [mailto:laurent.pinch...@ideasonboard.com] > Sent: Thursday, November 29, 2018 1:17 PM > To: Zhi, Yong > Cc: linux-media@vger.kernel.org; sakari.ai...@linux.intel.com; > tf...@chromium.org; mche...@kernel.org; hans.verk...@cisco.com; Mani, > Rajmohan ; Zheng, Jian Xu > ; Hu, Jerry W ; Toivonen, > Tuukka ; Qiu, Tian Shu > ; Cao, Bingbu > Subject: Re: [PATCH v7 01/16] v4l: Add Intel IPU3 meta buffer formats > > Hello Yong, > > Thank you for the patch. > > On Tuesday, 30 October 2018 00:22:55 EET Yong Zhi wrote: > > Add IPU3-specific meta formats for parameter processing and 3A, DVS > > statistics: > > Unless I'm mistaken DVS support has been removed. You can write this as > > Add IPU3-specific meta formats for processing parameters and 3A statistics. > Ack. > > > > V4L2_META_FMT_IPU3_PARAMS > > V4L2_META_FMT_IPU3_STAT_3A > > > > Signed-off-by: Yong Zhi > > --- > > drivers/media/v4l2-core/v4l2-ioctl.c | 2 ++ > > include/uapi/linux/videodev2.h | 4 > > 2 files changed, 6 insertions(+) > > I would squash this with patch 03/16. > OK, will squash patch 01 and 03 into single patch for v8. > > diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c > > b/drivers/media/v4l2-core/v4l2-ioctl.c index 6489f25..abff64b 100644 > > --- a/drivers/media/v4l2-core/v4l2-ioctl.c > > +++ b/drivers/media/v4l2-core/v4l2-ioctl.c > > @@ -1299,6 +1299,8 @@ static void v4l_fill_fmtdesc(struct v4l2_fmtdesc > *fmt) > > case V4L2_META_FMT_VSP1_HGO:descr = "R-Car VSP1 1-D Histogram"; > break; > > case V4L2_META_FMT_VSP1_HGT:descr = "R-Car VSP1 2-D Histogram"; > break; > > case V4L2_META_FMT_UVC: descr = "UVC payload header > metadata"; break; > > + case V4L2_META_FMT_IPU3_PARAMS: descr = "IPU3 processing > parameters"; > > break; > > + case V4L2_META_FMT_IPU3_STAT_3A:descr = "IPU3 3A statistics"; > break; > > > > default: > > /* Compressed formats */ > > diff --git a/include/uapi/linux/videodev2.h > > b/include/uapi/linux/videodev2.h index f0a968a..bdccd7a 100644 > > --- a/include/uapi/linux/videodev2.h > > +++ b/include/uapi/linux/videodev2.h > > @@ -718,6 +718,10 @@ struct v4l2_pix_format { > > #define V4L2_META_FMT_UVC v4l2_fourcc('U', 'V', 'C', 'H') /* UVC > > Payload Header metadata */ #define V4L2_META_FMT_D4XX > > v4l2_fourcc('D', '4', 'X', 'X') /* D4XX Payload Header metadata */ > > > > +/* Vendor specific - used for IPU3 camera sub-system */ > > +#define V4L2_META_FMT_IPU3_PARAMS v4l2_fourcc('i', 'p', '3', 'p') /* > IPU3 > > params */ > > Maybe "IPU3 processing parameters" in full ? > Ack, thanks!! > Apart from that the patch looks good to me. > > Reviewed-by: Laurent Pinchart > > > +#define V4L2_META_FMT_IPU3_STAT_3A v4l2_fourcc('i', 'p', '3', 's') /* > IPU3 > > 3A statistics */ > > + > > /* priv field value to indicates that subsequent fields are valid. */ > > #define V4L2_PIX_FMT_PRIV_MAGIC0xfeedcafe > > > -- > Regards, > > Laurent Pinchart > >
RE: [PATCH v7 03/16] v4l: Add Intel IPU3 meta data uAPI
Hi, Sakari, > -Original Message- > From: Sakari Ailus [mailto:sakari.ai...@linux.intel.com] > Sent: Thursday, November 29, 2018 4:46 PM > To: Zhi, Yong > Cc: linux-media@vger.kernel.org; tf...@chromium.org; > mche...@kernel.org; hans.verk...@cisco.com; > laurent.pinch...@ideasonboard.com; Mani, Rajmohan > ; Zheng, Jian Xu ; Hu, > Jerry W ; Toivonen, Tuukka > ; Qiu, Tian Shu ; Cao, > Bingbu ; Li, Chao C > Subject: Re: [PATCH v7 03/16] v4l: Add Intel IPU3 meta data uAPI > > Hi Yong, > > On Fri, Nov 16, 2018 at 10:37:00PM +, Zhi, Yong wrote: > ... > > > > +/** > > > > + * struct ipu3_uapi_shd_grid_config - Bayer shading(darkening) > > > > +correction > > > > + * > > > > + * @width: Grid horizontal dimensions, u8, [8, 128], default 73 > > > > + * @height:Grid vertical dimensions, u8, [8, 128], default 56 > > > > + * @block_width_log2: Log2 of the width of the grid cell in pixel > > > count > > > > + * u4, [0, 15], default value 5. > > > > + * @__reserved0: reserved > > > > + * @block_height_log2: Log2 of the height of the grid cell in pixel > > > count > > > > + * u4, [0, 15], default value 6. > > > > + * @__reserved1: reserved > > > > + * @grid_height_per_slice: SHD_MAX_CELLS_PER_SET/width. > > > > + * (with SHD_MAX_CELLS_PER_SET = > 146). > > > > + * @x_start: X value of top left corner of sensor relative to ROI > > > > + * u12, [-4096, 0]. default 0, only negative values. > > > > + * @y_start: Y value of top left corner of sensor relative to ROI > > > > + * u12, [-4096, 0]. default 0, only negative values. > > > > > > I suppose u12 is incorrect here, if the value is signed --- and > > > negative (sign bit) if not 0? > > > > > > > The value will be written to 13 bit register, should use s12.0. > > If you have s12, that means the most significant bit is the sign bit. So if > the > smallest value is -4096, you'd need s13. > > But where is the sign bit, i.e. is this either s13 or s16? > The notation of s12.0 means 13 bit with fraction bit as 0 right? > > > > > > + */ > > > > +struct ipu3_uapi_shd_grid_config { > > > > + /* reg 0 */ > > > > + __u8 width; > > > > + __u8 height; > > > > + __u8 block_width_log2:3; > > > > + __u8 __reserved0:1; > > > > + __u8 block_height_log2:3; > > > > + __u8 __reserved1:1; > > > > + __u8 grid_height_per_slice; > > > > + /* reg 1 */ > > > > + __s16 x_start; > > > > + __s16 y_start; > > > > +} __packed; > > ... > > > > > +/** > > > > + * struct ipu3_uapi_iefd_cux2_1 - Calculate power of non-directed > denoise > > > > + * element apply. > > > > + * @x0: X0 point of Config Unit, u9.0, default 0. > > > > + * @x1: X1 point of Config Unit, u9.0, default 0. > > > > + * @a01: Slope A of Config Unit, s4.4, default 0. > > > > > > The field is marked unsigned below. Which one is correct? > > > > > > > They are both correct, however, s4.4 is the internal representation > > used by CU, the inputs are unsigned, I will add a note in v8, same > > applies to the few other places as you commented. > > I still find this rather confusing. Is there a sign bit or is there not? > It's unsigned number from driver perspective, all CU inputs are unsigned, however, they will be "converted" to signed for FW/HW to use. I have to consult FW expert if more clarification is needed. > > > > > > + * @__reserved1: reserved > > > > + * @b01: offset B0 of Config Unit, u7.0, default 0. > > > > + * @__reserved2: reserved > > > > + */ > > > > +struct ipu3_uapi_iefd_cux2_1 { > > > > + __u32 x0:9; > > > > + __u32 x1:9; > > > > + __u32 a01:9; > > > > + __u32 __reserved1:5; > > > > + > > > > + __u32 b01:8; > > > > + __u32 __reserved2:24; > > > > +} __packed; > > > > + > > > > +/** > > > > + * struct ipu3_uapi_iefd_cux4 - Calculate power of non-directed > > > sharpening > > > > + * element. > > > > + * &g
Re: [PATCH v12 1/2] dt-bindings: media: Add Allwinner V3s Camera Sensor Interface (CSI)
Hi jacopo, On Fri, 23 Nov 2018 09:13:00 +0100 jacopo mondi wrote: > Hi Yong, > > On Fri, Nov 23, 2018 at 04:01:17PM +0800, Yong wrote: > > Hi jacopo, > > > > On Fri, 23 Nov 2018 08:45:14 +0100 > > jacopo mondi wrote: > > > > > Hi Yong, > > > > > > On Tue, Oct 30, 2018 at 03:06:24PM +0200, Laurent Pinchart wrote: > > > > Hi Yong, > > > > > > > > Thank you for the patch. > > > > > > > > On Tuesday, 30 October 2018 10:12:23 EET Yong Deng wrote: > > > > > Add binding documentation for Allwinner V3s CSI. > > > > > > > > > > Acked-by: Maxime Ripard > > > > > Acked-by: Sakari Ailus > > > > > Reviewed-by: Rob Herring > > > > > Signed-off-by: Yong Deng > > > > > > > > Reviewed-by: Laurent Pinchart > > > > > > > > > --- > > > > > .../devicetree/bindings/media/sun6i-csi.txt| 56 > > > > > +++ > > > > > 1 file changed, 56 insertions(+) > > > > > create mode 100644 > > > > > Documentation/devicetree/bindings/media/sun6i-csi.txt > > > > > > > > > > diff --git a/Documentation/devicetree/bindings/media/sun6i-csi.txt > > > > > b/Documentation/devicetree/bindings/media/sun6i-csi.txt new file mode > > > > > 100644 > > > > > index ..443e18c181b3 > > > > > --- /dev/null > > > > > +++ b/Documentation/devicetree/bindings/media/sun6i-csi.txt > > > > > @@ -0,0 +1,56 @@ > > > > > +Allwinner V3s Camera Sensor Interface > > > > > +- > > > > > + > > > > > +Allwinner V3s SoC features a CSI module(CSI1) with parallel > > > > > interface. > > > > > + > > > > > +Required properties: > > > > > + - compatible: value must be "allwinner,sun8i-v3s-csi" > > > > > + - reg: base address and size of the memory-mapped region. > > > > > + - interrupts: interrupt associated to this IP > > > > > + - clocks: phandles to the clocks feeding the CSI > > > > > +* bus: the CSI interface clock > > > > > +* mod: the CSI module clock > > > > > +* ram: the CSI DRAM clock > > > > > + - clock-names: the clock names mentioned above > > > > > + - resets: phandles to the reset line driving the CSI > > > > > + > > > > > +The CSI node should contain one 'port' child node with one child > > > > > 'endpoint' > > > > > +node, according to the bindings defined in > > > > > +Documentation/devicetree/bindings/media/video-interfaces.txt. > > > > > + > > > > > +Endpoint node properties for CSI > > > > > +- > > > > > +See the video-interfaces.txt for a detailed description of these > > > > > properties. +- remote-endpoint: (required) a phandle to the > > > > > bus receiver's > > > > > endpoint + node > > > > > +- bus-width: : (required) must be 8, 10, 12 or 16 > > > > > +- pclk-sample: (optional) (default: sample on > > > > > falling edge) > > > > > +- hsync-active : (required; parallel-only) > > > > > +- vsync-active : (required; parallel-only) > > > > > + > > > > > +Example: > > > > > + > > > > > +csi1: csi@1cb4000 { > > > > > + compatible = "allwinner,sun8i-v3s-csi"; > > > > > + reg = <0x01cb4000 0x1000>; > > > > > + interrupts = ; > > > > > + clocks = <&ccu CLK_BUS_CSI>, > > > > > + <&ccu CLK_CSI1_SCLK>, > > > > > + <&ccu CLK_DRAM_CSI>; > > > > > + clock-names = "bus", "mod", "ram"; > > > > > + resets = <&ccu RST_BUS_CSI>; > > > > > + > > > > > + port { > > > > > + /* Parallel bus endpoint */ > > > > > + csi1_ep: endpoint { > > > > > + remote-endpoint = <&adv7611_ep>; > > > > > + bus-width = <16
Re: [PATCH v12 1/2] dt-bindings: media: Add Allwinner V3s Camera Sensor Interface (CSI)
Hi jacopo, On Fri, 23 Nov 2018 08:45:14 +0100 jacopo mondi wrote: > Hi Yong, > > On Tue, Oct 30, 2018 at 03:06:24PM +0200, Laurent Pinchart wrote: > > Hi Yong, > > > > Thank you for the patch. > > > > On Tuesday, 30 October 2018 10:12:23 EET Yong Deng wrote: > > > Add binding documentation for Allwinner V3s CSI. > > > > > > Acked-by: Maxime Ripard > > > Acked-by: Sakari Ailus > > > Reviewed-by: Rob Herring > > > Signed-off-by: Yong Deng > > > > Reviewed-by: Laurent Pinchart > > > > > --- > > > .../devicetree/bindings/media/sun6i-csi.txt| 56 > > > +++ > > > 1 file changed, 56 insertions(+) > > > create mode 100644 Documentation/devicetree/bindings/media/sun6i-csi.txt > > > > > > diff --git a/Documentation/devicetree/bindings/media/sun6i-csi.txt > > > b/Documentation/devicetree/bindings/media/sun6i-csi.txt new file mode > > > 100644 > > > index ..443e18c181b3 > > > --- /dev/null > > > +++ b/Documentation/devicetree/bindings/media/sun6i-csi.txt > > > @@ -0,0 +1,56 @@ > > > +Allwinner V3s Camera Sensor Interface > > > +- > > > + > > > +Allwinner V3s SoC features a CSI module(CSI1) with parallel interface. > > > + > > > +Required properties: > > > + - compatible: value must be "allwinner,sun8i-v3s-csi" > > > + - reg: base address and size of the memory-mapped region. > > > + - interrupts: interrupt associated to this IP > > > + - clocks: phandles to the clocks feeding the CSI > > > +* bus: the CSI interface clock > > > +* mod: the CSI module clock > > > +* ram: the CSI DRAM clock > > > + - clock-names: the clock names mentioned above > > > + - resets: phandles to the reset line driving the CSI > > > + > > > +The CSI node should contain one 'port' child node with one child > > > 'endpoint' > > > +node, according to the bindings defined in > > > +Documentation/devicetree/bindings/media/video-interfaces.txt. > > > + > > > +Endpoint node properties for CSI > > > +- > > > +See the video-interfaces.txt for a detailed description of these > > > properties. +- remote-endpoint: (required) a phandle to the bus > > > receiver's > > > endpoint + node > > > +- bus-width: : (required) must be 8, 10, 12 or 16 > > > +- pclk-sample: (optional) (default: sample on falling edge) > > > +- hsync-active : (required; parallel-only) > > > +- vsync-active : (required; parallel-only) > > > + > > > +Example: > > > + > > > +csi1: csi@1cb4000 { > > > + compatible = "allwinner,sun8i-v3s-csi"; > > > + reg = <0x01cb4000 0x1000>; > > > + interrupts = ; > > > + clocks = <&ccu CLK_BUS_CSI>, > > > + <&ccu CLK_CSI1_SCLK>, > > > + <&ccu CLK_DRAM_CSI>; > > > + clock-names = "bus", "mod", "ram"; > > > + resets = <&ccu RST_BUS_CSI>; > > > + > > > + port { > > > + /* Parallel bus endpoint */ > > > + csi1_ep: endpoint { > > > + remote-endpoint = <&adv7611_ep>; > > > + bus-width = <16>; > > > + > > > + /* If hsync-active/vsync-active are missing, > > > +embedded BT.656 sync is used */ > > Am I confused? The properties description defines [v|h]sync-active as > required, but the example reports that they can be omitted to use > BT.656 synchronization. > > Which one of the following is correct? > 1) [h|v]sync-active are mandatory: no BT.656 support can be selected. > 2) [h|v]sync-active are optional, and if not specified BT.656 is >selected. > 3) I am confused. > hsync-active: (required; parallel-only) vsync-active: (required; parallel-only) Here, parallel means seperate sync signal, BT.656 means embedded sync signal. Kernel use these two properties to detect if the bus type is parallel or Bt656. So [h|v]sync-active are mandatory only if your bus type is parallel and must not be specified if your bus type is Bt656. Thanks, Yong
RE: [PATCH v7 03/16] v4l: Add Intel IPU3 meta data uAPI
Hi, Sakari, Thanks for the thorough review. > -Original Message- > From: Sakari Ailus [mailto:sakari.ai...@linux.intel.com] > Sent: Friday, November 2, 2018 8:03 AM > To: Zhi, Yong > Cc: linux-media@vger.kernel.org; tf...@chromium.org; > mche...@kernel.org; hans.verk...@cisco.com; > laurent.pinch...@ideasonboard.com; Mani, Rajmohan > ; Zheng, Jian Xu ; Hu, > Jerry W ; Toivonen, Tuukka > ; Qiu, Tian Shu ; Cao, > Bingbu ; Li, Chao C > Subject: Re: [PATCH v7 03/16] v4l: Add Intel IPU3 meta data uAPI > > Hi Yong, > > Thanks for the update! I went through this again... a few comments below > but I'd say they're mostly pretty minor issues. > > On Mon, Oct 29, 2018 at 03:22:57PM -0700, Yong Zhi wrote: > > These meta formats are used on Intel IPU3 ImgU video queues > > to carry 3A statistics and ISP pipeline parameters. > > > > V4L2_META_FMT_IPU3_3A > > V4L2_META_FMT_IPU3_PARAMS > > > > Signed-off-by: Yong Zhi > > Signed-off-by: Chao C Li > > Signed-off-by: Rajmohan Mani > > --- > > Documentation/media/uapi/v4l/meta-formats.rst |1 + > > .../media/uapi/v4l/pixfmt-meta-intel-ipu3.rst | 181 ++ > > include/uapi/linux/intel-ipu3.h| 2819 > > > > 3 files changed, 3001 insertions(+) > > create mode 100644 Documentation/media/uapi/v4l/pixfmt-meta-intel- > ipu3.rst > > create mode 100644 include/uapi/linux/intel-ipu3.h > > > > diff --git a/Documentation/media/uapi/v4l/meta-formats.rst > b/Documentation/media/uapi/v4l/meta-formats.rst > > index cf971d5..eafc534 100644 > > --- a/Documentation/media/uapi/v4l/meta-formats.rst > > +++ b/Documentation/media/uapi/v4l/meta-formats.rst > > @@ -12,6 +12,7 @@ These formats are used for the :ref:`metadata` > interface only. > > .. toctree:: > > :maxdepth: 1 > > > > +pixfmt-meta-intel-ipu3 > > pixfmt-meta-d4xx > > pixfmt-meta-uvc > > pixfmt-meta-vsp1-hgo > > diff --git a/Documentation/media/uapi/v4l/pixfmt-meta-intel-ipu3.rst > b/Documentation/media/uapi/v4l/pixfmt-meta-intel-ipu3.rst > > new file mode 100644 > > index 000..23b945b > > --- /dev/null > > +++ b/Documentation/media/uapi/v4l/pixfmt-meta-intel-ipu3.rst > > @@ -0,0 +1,181 @@ > > +.. -*- coding: utf-8; mode: rst -*- > > + > > +.. _intel-ipu3: > > Instead, to avoid a warning from Sphinx, replace the line with these: > > .. _v4l2-meta-fmt-ipu3-params: > .. _v4l2-meta-fmt-ipu3-stat-3a: > Ack. > > + > > > +*** > *** > > +V4L2_META_FMT_IPU3_PARAMS ('ip3p'), V4L2_META_FMT_IPU3_3A > ('ip3s') > > > +*** > *** > > + > > +.. c:type:: ipu3_uapi_stats_3a > > + > > +3A statistics > > += > > + > > +For IPU3 ImgU, the 3A statistics accelerators collect different statistics > > over > > +an input bayer frame. Those statistics, defined in data struct > > +:c:type:`ipu3_uapi_stats_3a`, are meta output obtained from "ipu3-imgu > 3a stat" > > +video node, which are then passed to user space for statistics analysis > > +using :c:type:`v4l2_meta_format` interface. > > + > > +The statistics collected are AWB (Auto-white balance) RGBS (Red, Green, > Blue and > > Extra whitespace at the end of the line. > Ack. > > +Saturation measure) cells, AWB filter response, AF (Auto-focus) filter > response, > > +and AE (Auto-exposure) histogram. > > + > > +struct :c:type:`ipu3_uapi_4a_config` saves configurable parameters for all > above. > > + > > + > > +.. code-block:: c > > + > > + > > + struct ipu3_uapi_stats_3a { > > + struct ipu3_uapi_awb_raw_buffer awb_raw_buffer > > +__attribute__((aligned(32))); > > + struct ipu3_uapi_ae_raw_buffer_aligned > > + ae_raw_buffer[IPU3_UAPI_MAX_STRIPES]; > > + struct ipu3_uapi_af_raw_buffer af_raw_buffer; > > + struct ipu3_uapi_awb_fr_raw_buffer awb_fr_raw_buffer; > > + struct ipu3_uapi_4a_config stats_4a_config; > > + __u32 ae_join_buffers; > > + __u8 padding[28]; > > + struct ipu3_uapi_stats_3a_bubble_info_per_stripe > > + stats_3a_bubble_per_stripe; > > I think you could just unwrap these, even if it causes them to be over 80 > characters per line. They display better in a web browser that way. Or > alternatively align the wrapped lines to the same column. > Ack
RE: [PATCH v7 14/16] intel-ipu3: Add v4l2 driver based on media framework
Hi, Hans, Thanks for the review. > -Original Message- > From: Hans Verkuil [mailto:hverk...@xs4all.nl] > Sent: Thursday, November 15, 2018 6:51 AM > To: Zhi, Yong ; linux-media@vger.kernel.org; > sakari.ai...@linux.intel.com > Cc: tf...@chromium.org; mche...@kernel.org; hans.verk...@cisco.com; > laurent.pinch...@ideasonboard.com; Mani, Rajmohan > ; Zheng, Jian Xu ; Hu, > Jerry W ; Toivonen, Tuukka > ; Qiu, Tian Shu ; Cao, > Bingbu > Subject: Re: [PATCH v7 14/16] intel-ipu3: Add v4l2 driver based on media > framework > > On 10/29/18 23:23, Yong Zhi wrote: > > Implement video driver that utilizes v4l2, vb2 queue support and media > > controller APIs. The driver exposes single subdevice and six nodes. > > > > Signed-off-by: Yong Zhi > > --- > > drivers/media/pci/intel/ipu3/ipu3-v4l2.c | 1091 > > ++ > > 1 file changed, 1091 insertions(+) > > create mode 100644 drivers/media/pci/intel/ipu3/ipu3-v4l2.c > > > > diff --git a/drivers/media/pci/intel/ipu3/ipu3-v4l2.c > > b/drivers/media/pci/intel/ipu3/ipu3-v4l2.c > > > > > +int ipu3_v4l2_register(struct imgu_device *imgu) { > > > > > + /* Initialize vbq */ > > + vbq->type = node->vdev_fmt.type; > > + vbq->io_modes = VB2_USERPTR | VB2_MMAP | > VB2_DMABUF; > > Are you sure USERPTR works? If you have alignment requirements that the > buffer starts at a multiple of more than (I think) 8 bytes, then USERPTR won't > work. USRPTR was used at the beginning of project, we then switched to dma buffer mainly for performance reason: https://chromium-review.googlesource.com/c/chromiumos/platform/arc-camera/+/620252 > > > + vbq->ops = &ipu3_vb2_ops; > > + vbq->mem_ops = &vb2_dma_sg_memops; > > + if (imgu->buf_struct_size <= 0) > > + imgu->buf_struct_size = sizeof(struct > ipu3_vb2_buffer); > > + vbq->buf_struct_size = imgu->buf_struct_size; > > + vbq->timestamp_flags = > V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC; > > + vbq->min_buffers_needed = 0;/* Can streamon w/o buffers > */ > > + vbq->drv_priv = imgu; > > + vbq->lock = &node->lock; > > + r = vb2_queue_init(vbq); > > + if (r) { > > + dev_err(&imgu->pci_dev->dev, > > + "failed to initialize video queue (%d)\n", r); > > + goto fail_vdev; > > + } > > + > > + /* Initialize vdev */ > > + snprintf(vdev->name, sizeof(vdev->name), "%s %s", > > +IMGU_NAME, node->name); > > + vdev->release = video_device_release_empty; > > + vdev->fops = &ipu3_v4l2_fops; > > + vdev->lock = &node->lock; > > + vdev->v4l2_dev = &imgu->v4l2_dev; > > + vdev->queue = &node->vbq; > > + vdev->vfl_dir = node->output ? VFL_DIR_TX : VFL_DIR_RX; > > + video_set_drvdata(vdev, imgu); > > + r = video_register_device(vdev, VFL_TYPE_GRABBER, -1); > > + if (r) { > > + dev_err(&imgu->pci_dev->dev, > > + "failed to register video device (%d)\n", r); > > + goto fail_vdev; > > + } > > + > > + /* Create link between video node and the subdev pad */ > > + flags = 0; > > + if (node->enabled) > > + flags |= MEDIA_LNK_FL_ENABLED; > > + if (node->immutable) > > + flags |= MEDIA_LNK_FL_IMMUTABLE; > > + if (node->output) { > > + r = media_create_pad_link(&vdev->entity, 0, > > + &imgu->subdev.entity, > > +i, flags); > > + } else { > > + r = media_create_pad_link(&imgu->subdev.entity, > > + i, &vdev->entity, 0, flags); > > + } > > + if (r) > > + goto fail_link; > > + } > > + > > + r = media_device_register(&imgu->media_dev); > > + if (r) { > > + dev_err(&imgu->pci_dev->dev, > > + "failed to register media device (%d)\n", r); > > + i-
Re: [PATCH v12 0/2] Initial Allwinner V3s CSI Support
Hi Maxime, On Tue, 13 Nov 2018 14:35:18 +0100 Maxime Ripard wrote: > Hi Yong, > > On Tue, Oct 30, 2018 at 04:09:48PM +0800, Yong Deng wrote: > > I can't make v4l2-compliance always happy. > > The V3s CSI support many pixformats. But they are not always available. > > It's dependent on the input bus format (MEDIA_BUS_FMT_*). > > Example: > > V4L2_PIX_FMT_SBGGR8: MEDIA_BUS_FMT_SBGGR8_1X8 > > V4L2_PIX_FMT_YUYV: MEDIA_BUS_FMT_YUYV8_2X8 > > But I can't get the subdev's format code before starting stream as the > > subdev may change it. So I can't know which pixformats are available. > > So I exports all the pixformats supported by SoC. > > The result is the app (v4l2-compliance) is likely to fail on streamon. > > > > This patchset add initial support for Allwinner V3s CSI. > > > > Allwinner V3s SoC features a CSI module with parallel interface. > > > > This patchset implement a v4l2 framework driver and add a binding > > documentation for it. > > I've tested this version today, and I needed this patch to make it > work on top of v4.20: > http://code.bulix.org/9o8fw5-503690?raw > > Once that patch applied, my tests were working as expected. > > If that make sense, could you resubmit a new version with these merged > so that we can try to target 4.21? OK. I will check it. Thanks, Yong
RE: [PATCH v7 15/16] intel-ipu3: Add imgu top level pci device driver
Hi, Sakari, Thanks again for the code review. > -Original Message- > From: Sakari Ailus [mailto:sakari.ai...@linux.intel.com] > Sent: Friday, November 9, 2018 6:54 AM > To: Zhi, Yong > Cc: linux-media@vger.kernel.org; tf...@chromium.org; > mche...@kernel.org; hans.verk...@cisco.com; > laurent.pinch...@ideasonboard.com; Mani, Rajmohan > ; Zheng, Jian Xu ; Hu, > Jerry W ; Toivonen, Tuukka > ; Qiu, Tian Shu ; Cao, > Bingbu > Subject: Re: [PATCH v7 15/16] intel-ipu3: Add imgu top level pci device driver > > Hi Yong, > > On Mon, Oct 29, 2018 at 03:23:09PM -0700, Yong Zhi wrote: > > This patch adds support for the Intel IPU v3 as found on Skylake and > > Kaby Lake SoCs. > > > > The driver glues v4l2, css(camera sub system) and other pieces > > together to perform its functions, it also loads the IPU3 firmware > > binary as part of its initialization. > > > > Signed-off-by: Yong Zhi > > Signed-off-by: Tomasz Figa > > --- > > drivers/media/pci/intel/ipu3/Kconfig | 16 + > > drivers/media/pci/intel/ipu3/Makefile | 12 + > > drivers/media/pci/intel/ipu3/ipu3.c | 844 > ++ > > drivers/media/pci/intel/ipu3/ipu3.h | 153 ++ > > 4 files changed, 1025 insertions(+) > > create mode 100644 drivers/media/pci/intel/ipu3/ipu3.c > > create mode 100644 drivers/media/pci/intel/ipu3/ipu3.h > > > > diff --git a/drivers/media/pci/intel/ipu3/Kconfig > > b/drivers/media/pci/intel/ipu3/Kconfig > > index 715f776..44ebcbb 100644 > > --- a/drivers/media/pci/intel/ipu3/Kconfig > > +++ b/drivers/media/pci/intel/ipu3/Kconfig > > @@ -15,3 +15,19 @@ config VIDEO_IPU3_CIO2 > > Say Y or M here if you have a Skylake/Kaby Lake SoC with MIPI CSI-2 > > connected camera. > > The module will be called ipu3-cio2. > > + > > +config VIDEO_IPU3_IMGU > > + tristate "Intel ipu3-imgu driver" > > + depends on PCI && VIDEO_V4L2 > > + depends on MEDIA_CONTROLLER && VIDEO_V4L2_SUBDEV_API > > + depends on X86 > > + select IOMMU_IOVA > > + select VIDEOBUF2_DMA_SG > > + > > Extra newline. > Ack. > > + ---help--- > > + This is the video4linux2 driver for Intel IPU3 image processing > > +unit, > > "Video4Linux2" > Ack. > > + found in Intel Skylake and Kaby Lake SoCs and used for processing > > + images and video. > > + > > + Say Y or M here if you have a Skylake/Kaby Lake SoC with a MIPI > > + camera. The module will be called ipu3-imgu. > > The latter tab should be a space only. > Ack. > > diff --git a/drivers/media/pci/intel/ipu3/Makefile > > b/drivers/media/pci/intel/ipu3/Makefile > > index 20186e3..60bd5db 100644 > > --- a/drivers/media/pci/intel/ipu3/Makefile > > +++ b/drivers/media/pci/intel/ipu3/Makefile > > @@ -1 +1,13 @@ > > +# > > +# Makefile for the IPU3 cio2 and ImgU drivers # > > + > > obj-$(CONFIG_VIDEO_IPU3_CIO2) += ipu3-cio2.o > > + > > +ipu3-imgu-objs += \ > > + ipu3-mmu.o ipu3-dmamap.o \ > > + ipu3-tables.o ipu3-css-pool.o \ > > + ipu3-css-fw.o ipu3-css-params.o \ > > + ipu3-css.o ipu3-v4l2.o ipu3.o > > + > > +obj-$(CONFIG_VIDEO_IPU3_IMGU) += ipu3-imgu.o > > diff --git a/drivers/media/pci/intel/ipu3/ipu3.c > > b/drivers/media/pci/intel/ipu3/ipu3.c > > new file mode 100644 > > index 000..eda7299 > > --- /dev/null > > +++ b/drivers/media/pci/intel/ipu3/ipu3.c > > @@ -0,0 +1,844 @@ > > +// SPDX-License-Identifier: GPL-2.0 > > +/* > > + * Copyright (C) 2017 Intel Corporation > > + * Copyright 2017 Google LLC > > + * > > + * Based on Intel IPU4 driver. > > + * > > + */ > > + > > +#include > > +#include > > +#include > > +#include > > + > > +#include "ipu3.h" > > +#include "ipu3-dmamap.h" > > +#include "ipu3-mmu.h" > > + > > +#define IMGU_PCI_ID0x1919 > > +#define IMGU_PCI_BAR 0 > > +#define IMGU_DMA_MASK DMA_BIT_MASK(39) > > +#define IMGU_MAX_QUEUE_DEPTH (2 + 2) > > + > > +/* > > + * pre-allocated buffer size for IMGU dummy buffers. Those > > + * values should be tuned to big enough to avoid buffer > > + * re-allocation when streaming to lower streaming latency. > > + */ > > +#define CSS_QUEUE_IN_BUF_SIZE 0 > > +#define CSS_QUEUE_PARAMS_BUF_SI
RE: [PATCH v7 14/16] intel-ipu3: Add v4l2 driver based on media framework
Hi, Sakari, Thanks for the feedback. > -Original Message- > From: Sakari Ailus [mailto:sakari.ai...@linux.intel.com] > Sent: Friday, November 9, 2018 6:37 AM > To: Zhi, Yong > Cc: linux-media@vger.kernel.org; tf...@chromium.org; > mche...@kernel.org; hans.verk...@cisco.com; > laurent.pinch...@ideasonboard.com; Mani, Rajmohan > ; Zheng, Jian Xu ; Hu, > Jerry W ; Toivonen, Tuukka > ; Qiu, Tian Shu ; Cao, > Bingbu > Subject: Re: [PATCH v7 14/16] intel-ipu3: Add v4l2 driver based on media > framework > > Hi Yong, > > On Mon, Oct 29, 2018 at 03:23:08PM -0700, Yong Zhi wrote: > > Implement video driver that utilizes v4l2, vb2 queue support and media > > controller APIs. The driver exposes single subdevice and six nodes. > > > > Signed-off-by: Yong Zhi > > --- > > drivers/media/pci/intel/ipu3/ipu3-v4l2.c | 1091 > > ++ > > 1 file changed, 1091 insertions(+) > > create mode 100644 drivers/media/pci/intel/ipu3/ipu3-v4l2.c > > > > diff --git a/drivers/media/pci/intel/ipu3/ipu3-v4l2.c > > b/drivers/media/pci/intel/ipu3/ipu3-v4l2.c > > new file mode 100644 > > index 000..31a3514 > > --- /dev/null > > +++ b/drivers/media/pci/intel/ipu3/ipu3-v4l2.c > > @@ -0,0 +1,1091 @@ > > +// SPDX-License-Identifier: GPL-2.0 > > +// Copyright (C) 2018 Intel Corporation > > + > > +#include > > +#include > > + > > +#include > > + > > +#include "ipu3.h" > > +#include "ipu3-dmamap.h" > > + > > +/ v4l2_subdev_ops / > > + > > +static int ipu3_subdev_open(struct v4l2_subdev *sd, struct > > +v4l2_subdev_fh *fh) { > > + struct imgu_device *imgu = container_of(sd, struct imgu_device, > subdev); > > + struct v4l2_rect try_crop = { > > + .top = 0, > > + .left = 0, > > + .height = imgu- > >nodes[IMGU_NODE_IN].vdev_fmt.fmt.pix_mp.height, > > + .width = imgu- > >nodes[IMGU_NODE_IN].vdev_fmt.fmt.pix_mp.width, > > + }; > > + unsigned int i; > > + > > + /* Initialize try_fmt */ > > + for (i = 0; i < IMGU_NODE_NUM; i++) > > + *v4l2_subdev_get_try_format(sd, fh->pad, i) = > > + imgu->nodes[i].pad_fmt; > > The try formats should reflect the defaults, not the current device state. > Ack, will fix in next update. > > + > > + *v4l2_subdev_get_try_crop(sd, fh->pad, IMGU_NODE_IN) = try_crop; > > Same for the crop. How about the compose rectangle? > Ok, will check both crop and compose rectangle. > > + > > + return 0; > > +} > > ... > > > +int ipu3_v4l2_register(struct imgu_device *imgu) { > > + struct v4l2_mbus_framefmt def_bus_fmt = { 0 }; > > + struct v4l2_pix_format_mplane def_pix_fmt = { 0 }; > > + > > Extra newline. Ack. > > > + int i, r; > > + > > + /* Initialize miscellaneous variables */ > > + imgu->streaming = false; > > + > > + /* Init media device */ > > + media_device_pci_init(&imgu->media_dev, imgu->pci_dev, > IMGU_NAME); > > + > > + /* Set up v4l2 device */ > > + imgu->v4l2_dev.mdev = &imgu->media_dev; > > + imgu->v4l2_dev.ctrl_handler = imgu->ctrl_handler; > > + r = v4l2_device_register(&imgu->pci_dev->dev, &imgu->v4l2_dev); > > + if (r) { > > + dev_err(&imgu->pci_dev->dev, > > + "failed to register V4L2 device (%d)\n", r); > > + goto fail_v4l2_dev; > > + } > > + > > + /* Initialize subdev media entity */ > > + imgu->subdev_pads = kzalloc(sizeof(*imgu->subdev_pads) * > > + IMGU_NODE_NUM, GFP_KERNEL); > > As the number of pads is static, could you instead put the array directly to > the struct, instead of using a pointer? Remember to remove to > corresponding kfree, too. Good point, kzalloc does not serve its purpose here. > > > + if (!imgu->subdev_pads) { > > + r = -ENOMEM; > > + goto fail_subdev_pads; > > + } > > + r = media_entity_pads_init(&imgu->subdev.entity, > IMGU_NODE_NUM, > > + imgu->subdev_pads); > > + if (r) { > > + dev_err(&imgu->pci_dev->dev, > > + "failed initialize subdev media entity (%d)\n", r); > > + goto fail_media_entity; > > + } > > + imgu->
RE: [PATCH v7 08/16] intel-ipu3: css: Add dma buff pool utility functions
Hi, Sakari, > -Original Message- > From: Sakari Ailus [mailto:sakari.ai...@linux.intel.com] > Sent: Thursday, November 8, 2018 9:36 AM > To: Zhi, Yong > Cc: linux-media@vger.kernel.org; tf...@chromium.org; > mche...@kernel.org; hans.verk...@cisco.com; > laurent.pinch...@ideasonboard.com; Mani, Rajmohan > ; Zheng, Jian Xu ; Hu, > Jerry W ; Toivonen, Tuukka > ; Qiu, Tian Shu ; Cao, > Bingbu > Subject: Re: [PATCH v7 08/16] intel-ipu3: css: Add dma buff pool utility > functions > > Hi Yong, > > On Mon, Oct 29, 2018 at 03:23:02PM -0700, Yong Zhi wrote: > > The pools are used to store previous parameters set by user with the > > parameter queue. Due to pipelining, there needs to be multiple sets > > (up to four) of parameters which are queued in a host-to-sp queue. > > > > Signed-off-by: Yong Zhi > > --- > > drivers/media/pci/intel/ipu3/ipu3-css-pool.c | 136 > > +++ > > drivers/media/pci/intel/ipu3/ipu3-css-pool.h | 56 +++ > > 2 files changed, 192 insertions(+) > > create mode 100644 drivers/media/pci/intel/ipu3/ipu3-css-pool.c > > create mode 100644 drivers/media/pci/intel/ipu3/ipu3-css-pool.h > > > > diff --git a/drivers/media/pci/intel/ipu3/ipu3-css-pool.c > > b/drivers/media/pci/intel/ipu3/ipu3-css-pool.c > > new file mode 100644 > > index 000..eab41c3 > > --- /dev/null > > +++ b/drivers/media/pci/intel/ipu3/ipu3-css-pool.c > > @@ -0,0 +1,136 @@ > > +// SPDX-License-Identifier: GPL-2.0 > > +// Copyright (C) 2018 Intel Corporation > > + > > +#include > > + > > +#include "ipu3.h" > > +#include "ipu3-css-pool.h" > > +#include "ipu3-dmamap.h" > > + > > +int ipu3_css_dma_buffer_resize(struct imgu_device *imgu, > > + struct ipu3_css_map *map, size_t size) { > > + if (map->size < size && map->vaddr) { > > + dev_warn(&imgu->pci_dev->dev, "dma buf resized from %zu > to %zu", > > +map->size, size); > > + > > + ipu3_dmamap_free(imgu, map); > > + if (!ipu3_dmamap_alloc(imgu, map, size)) > > + return -ENOMEM; > > + } > > + > > + return 0; > > +} > > + > > +void ipu3_css_pool_cleanup(struct imgu_device *imgu, struct > > +ipu3_css_pool *pool) { > > + unsigned int i; > > + > > + for (i = 0; i < IPU3_CSS_POOL_SIZE; i++) > > + ipu3_dmamap_free(imgu, &pool->entry[i].param); } > > + > > +int ipu3_css_pool_init(struct imgu_device *imgu, struct ipu3_css_pool > *pool, > > + size_t size) > > +{ > > + unsigned int i; > > + > > + for (i = 0; i < IPU3_CSS_POOL_SIZE; i++) { > > + /* > > +* entry[i].framenum is initialized to INT_MIN so that > > +* ipu3_css_pool_check() can treat it as usesable slot. > > +*/ > > + pool->entry[i].framenum = INT_MIN; > > + > > + if (size == 0) { > > + pool->entry[i].param.vaddr = NULL; > > + continue; > > + } > > + > > + if (!ipu3_dmamap_alloc(imgu, &pool->entry[i].param, size)) > > + goto fail; > > + } > > + > > + pool->last = IPU3_CSS_POOL_SIZE; > > + > > + return 0; > > + > > +fail: > > + ipu3_css_pool_cleanup(imgu, pool); > > + return -ENOMEM; > > +} > > + > > +/* > > + * Check that the following call to pool_get succeeds. > > + * Return negative on error. > > + */ > > +static int ipu3_css_pool_check(struct ipu3_css_pool *pool, long > > +framenum) { > > + /* Get the oldest entry */ > > + int n = (pool->last + 1) % IPU3_CSS_POOL_SIZE; > > + long diff = framenum - pool->entry[n].framenum; > > + > > + /* if framenum wraps around and becomes smaller than entry n */ > > + if (diff < 0) > > + diff += LONG_MAX; > > Have you tested the wrap-around? As a result, the value of the diff is > between -1 and LONG_MAX - 1 (without considering more than just the two > lines above). Is that intended? > Yes, I simulated wrap-around using a smaller limit in v5. > You seem to be using different types for the frame number; sometimes int, > sometimes long. Could you align that, preferrably to an unsigned type? u32 > would probably be a sound choice. > Will use u32 at places except entry.framenum, which is initialized to INT_
RE: [PATCH v7 00/16] Intel IPU3 ImgU patchset
Hi, Sakari, Thanks for your review and comments. Bingbu has replied to some of your questions, so I will continue with the rest. > -Original Message- > From: Bing Bu Cao [mailto:bingbu@linux.intel.com] > Sent: Tuesday, November 6, 2018 10:17 PM > To: Sakari Ailus ; Zhi, Yong > > Cc: linux-media@vger.kernel.org; tf...@chromium.org; > mche...@kernel.org; hans.verk...@cisco.com; > laurent.pinch...@ideasonboard.com; Mani, Rajmohan > ; Zheng, Jian Xu ; Hu, > Jerry W ; Toivonen, Tuukka > ; Qiu, Tian Shu ; Cao, > Bingbu > Subject: Re: [PATCH v7 00/16] Intel IPU3 ImgU patchset > > > On 11/01/2018 08:03 PM, Sakari Ailus wrote: > > Hi Yong, > > > > Thanks for the update! > > > > On Mon, Oct 29, 2018 at 03:22:54PM -0700, Yong Zhi wrote: > >> Hi, > >> > >> This series adds support for the Intel IPU3 (Image Processing Unit) > >> ImgU which is essentially a modern memory-to-memory ISP. It > >> implements raw Bayer to YUV image format conversion as well as a > >> large number of other pixel processing algorithms for improving the image > quality. > >> > >> Meta data formats are defined for image statistics (3A, i.e. > >> automatic white balance, exposure and focus, histogram and local area > >> contrast > >> enhancement) as well as for the pixel processing algorithm parameters. > >> The documentation for these formats is currently not included in the > >> patchset but will be added in a future version of this set. > >> > >> The algorithm parameters need to be considered specific to a given > >> frame and typically a large number of these parameters change on > >> frame to frame basis. Additionally, the parameters are highly > >> structured (and not a flat space of independent configuration > >> primitives). They also reflect the data structures used by the > >> firmware and the hardware. On top of that, the algorithms require > >> highly specialized user space to make meaningful use of them. For > >> these reasons it has been chosen video buffers to pass the parameters to > the device. > >> > >> On individual patches: > >> > >> The heart of ImgU is the CSS, or Camera Subsystem, which contains the > >> image processors and HW accelerators. > >> > >> The 3A statistics and other firmware parameter computation related > >> functions are implemented in patch 11. > >> > >> All IPU3 pipeline default settings can be found in patch 10. > >> > >> To access DDR via ImgU's own memory space, IPU3 is also equipped with > >> its own MMU unit, the driver is implemented in patch 6. > >> > >> Patch 7 uses above driver for DMA mapping operation. > >> > >> The communication between IPU3 firmware and driver is implemented > >> with circular queues in patch 8. > >> > >> Patch 9 provide some utility functions and manage IPU3 fw download > >> and install. > >> > >> The firmware which is called ipu3-fw.bin can be downloaded from: > >> > >> git://git.kernel.org/pub/scm/linux/kernel/git/firmware/linux-firmware > >> .git (commit 2c27b0cb02f18c022d8378e0e1abaf8b7ae8188f) > >> > >> Firmware ABI is defined in patches 4 and 5. > >> > >> Patches 12 and 13 are of the same file, the former contains all h/w > >> programming related code, the latter implements interface functions > >> for access fw & hw capabilities. > >> > >> Patch 14 has a dependency on Sakari's V4L2_BUF_TYPE_META_OUTPUT > work: > >> > >> https://patchwork.kernel.org/patch/9976295/> > > I've pushed the latest set here: > > > > https://git.linuxtv.org/sailus/media_tree.git/log/?h=meta-output> > > > > You can just say the entire set depends on those going forward; the > > documentation is needed, too. > > Ack. > >> Patch 15 represents the top level that glues all of the other > >> components together, passing arguments between the components. > >> > >> Patch 16 is a recent effort to extend v6 for advanced camera features > >> like Continuous View Finder (CVF) and Snapshot During Video(SDV) > support. > >> > >> Link to user space implementation: > >> > >> git clone > >> https://chromium.googlesource.com/chromiumos/platform/arc-camera > >> > >> ImgU media topology print: > >> > >> # media-ctl -d /dev/media0 -p > >> Media controller API version 4.19.0 > >> > >
RE: [PATCH v7 03/16] v4l: Add Intel IPU3 meta data uAPI
Hi, Mauro, Thanks for your review. > -Original Message- > From: Mauro Carvalho Chehab [mailto:mchehab+sams...@kernel.org] > Sent: Friday, November 2, 2018 6:49 AM > To: Zhi, Yong > Cc: linux-media@vger.kernel.org; sakari.ai...@linux.intel.com; > tf...@chromium.org; hans.verk...@cisco.com; > laurent.pinch...@ideasonboard.com; Mani, Rajmohan > ; Zheng, Jian Xu ; Hu, > Jerry W ; Toivonen, Tuukka > ; Qiu, Tian Shu ; Cao, > Bingbu ; Li, Chao C > Subject: Re: [PATCH v7 03/16] v4l: Add Intel IPU3 meta data uAPI > > Em Mon, 29 Oct 2018 15:22:57 -0700 > Yong Zhi escreveu: > > > These meta formats are used on Intel IPU3 ImgU video queues > > to carry 3A statistics and ISP pipeline parameters. > > Just minor things. See below. > > > > > V4L2_META_FMT_IPU3_3A > > V4L2_META_FMT_IPU3_PARAMS > > > > Signed-off-by: Yong Zhi > > Signed-off-by: Chao C Li > > Signed-off-by: Rajmohan Mani > > --- > > Documentation/media/uapi/v4l/meta-formats.rst |1 + > > .../media/uapi/v4l/pixfmt-meta-intel-ipu3.rst | 181 ++ > > I would actually prefer to have those two changes merged together with > patch 1, as it makes easier for review. > > > include/uapi/linux/intel-ipu3.h| 2819 > > > > This one makes sense to have a separate patch. > Ack, will re-group the three files as suggested. > > 3 files changed, 3001 insertions(+) > > create mode 100644 Documentation/media/uapi/v4l/pixfmt-meta-intel- > ipu3.rst > > create mode 100644 include/uapi/linux/intel-ipu3.h > > > > diff --git a/Documentation/media/uapi/v4l/meta-formats.rst > b/Documentation/media/uapi/v4l/meta-formats.rst > > index cf971d5..eafc534 100644 > > --- a/Documentation/media/uapi/v4l/meta-formats.rst > > +++ b/Documentation/media/uapi/v4l/meta-formats.rst > > @@ -12,6 +12,7 @@ These formats are used for the :ref:`metadata` > interface only. > > .. toctree:: > > :maxdepth: 1 > > > > +pixfmt-meta-intel-ipu3 > > pixfmt-meta-d4xx > > pixfmt-meta-uvc > > pixfmt-meta-vsp1-hgo > > diff --git a/Documentation/media/uapi/v4l/pixfmt-meta-intel-ipu3.rst > b/Documentation/media/uapi/v4l/pixfmt-meta-intel-ipu3.rst > > new file mode 100644 > > index 000..23b945b > > --- /dev/null > > +++ b/Documentation/media/uapi/v4l/pixfmt-meta-intel-ipu3.rst > > @@ -0,0 +1,181 @@ > > +.. -*- coding: utf-8; mode: rst -*- > > + > > +.. _intel-ipu3: > > + > > > +*** > *** > > +V4L2_META_FMT_IPU3_PARAMS ('ip3p'), V4L2_META_FMT_IPU3_3A > ('ip3s') > > > +*** > *** > > + > > +.. c:type:: ipu3_uapi_stats_3a > > + > > +3A statistics > > += > > + > > +For IPU3 ImgU, the 3A statistics accelerators collect different statistics > > over > > +an input bayer frame. Those statistics, defined in data struct > > +:c:type:`ipu3_uapi_stats_3a`, are meta output obtained from "ipu3-imgu > 3a stat" > > +video node, which are then passed to user space for statistics analysis > > +using :c:type:`v4l2_meta_format` interface. > > + > > +The statistics collected are AWB (Auto-white balance) RGBS (Red, Green, > Blue and > > +Saturation measure) cells, AWB filter response, AF (Auto-focus) filter > response, > > +and AE (Auto-exposure) histogram. > > + > > +struct :c:type:`ipu3_uapi_4a_config` saves configurable parameters for all > above. > > + > > + > > +.. code-block:: c > > + > > + > > + struct ipu3_uapi_stats_3a { > > + struct ipu3_uapi_awb_raw_buffer awb_raw_buffer > > +__attribute__((aligned(32))); > > + struct ipu3_uapi_ae_raw_buffer_aligned > > + ae_raw_buffer[IPU3_UAPI_MAX_STRIPES]; > > + struct ipu3_uapi_af_raw_buffer af_raw_buffer; > > + struct ipu3_uapi_awb_fr_raw_buffer awb_fr_raw_buffer; > > + struct ipu3_uapi_4a_config stats_4a_config; > > + __u32 ae_join_buffers; > > + __u8 padding[28]; > > + struct ipu3_uapi_stats_3a_bubble_info_per_stripe > > + stats_3a_bubble_per_stripe; > > + struct ipu3_uapi_ff_status stats_3a_status; > > + } __packed; > > + > > + > > +.. c:type:: ipu3_uapi_params > > + > > +Pipeline parameters > > +=== > > +
[PATCH] [v4l-utils] libv4l2subdev: Add MEDIA_BUS_FMT_FIXED to mbus_formats[]
Also add V4L2_COLORSPACE_RAW to the colorspaces[]. Signed-off-by: Yong Zhi --- utils/media-ctl/libv4l2subdev.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/utils/media-ctl/libv4l2subdev.c b/utils/media-ctl/libv4l2subdev.c index a989efb..46668eb 100644 --- a/utils/media-ctl/libv4l2subdev.c +++ b/utils/media-ctl/libv4l2subdev.c @@ -855,6 +855,7 @@ static const struct { enum v4l2_mbus_pixelcode code; } mbus_formats[] = { #include "media-bus-format-names.h" + { "FIXED", MEDIA_BUS_FMT_FIXED}, { "Y8", MEDIA_BUS_FMT_Y8_1X8}, { "Y10", MEDIA_BUS_FMT_Y10_1X10 }, { "Y12", MEDIA_BUS_FMT_Y12_1X12 }, @@ -965,7 +966,9 @@ static struct { { "srgb", V4L2_COLORSPACE_SRGB }, { "oprgb", V4L2_COLORSPACE_OPRGB }, { "bt2020", V4L2_COLORSPACE_BT2020 }, + { "raw", V4L2_COLORSPACE_RAW }, { "dcip3", V4L2_COLORSPACE_DCI_P3 }, + }; const char *v4l2_subdev_colorspace_to_string(enum v4l2_colorspace colorspace) -- 2.7.4
RE: [PATCH v7 06/16] intel-ipu3: mmu: Implement driver
Hi, Sakari, Thanks for the feedback. > -Original Message- > From: Sakari Ailus [mailto:sakari.ai...@linux.intel.com] > Sent: Monday, November 5, 2018 3:55 AM > To: Zhi, Yong > Cc: linux-media@vger.kernel.org; tf...@chromium.org; > mche...@kernel.org; hans.verk...@cisco.com; > laurent.pinch...@ideasonboard.com; Mani, Rajmohan > ; Zheng, Jian Xu ; Hu, > Jerry W ; Toivonen, Tuukka > ; Qiu, Tian Shu ; Cao, > Bingbu > Subject: Re: [PATCH v7 06/16] intel-ipu3: mmu: Implement driver > > Hi Yong, > > On Mon, Oct 29, 2018 at 03:23:00PM -0700, Yong Zhi wrote: > > From: Tomasz Figa > > > > This driver translates IO virtual address to physical address based on > > two levels page tables. > > > > Signed-off-by: Tomasz Figa > > Signed-off-by: Yong Zhi > > --- > > ... > > > +static void call_if_ipu3_is_powered(struct ipu3_mmu *mmu, > > + void (*func)(struct ipu3_mmu *mmu)) { > > + pm_runtime_get_noresume(mmu->dev); > > + if (pm_runtime_active(mmu->dev)) > > + func(mmu); > > + pm_runtime_put(mmu->dev); > > How about: > > if (!pm_runtime_get_if_in_use(mmu->dev)) > return; > > func(mmu); > pm_runtime_put(mmu->dev); > Ack, unless Tomasz has different opinion. > > > +} > > -- > Sakari Ailus > sakari.ai...@linux.intel.com
[PATCH v12 2/2] media: V3s: Add support for Allwinner CSI.
Allwinner V3s SoC features a CSI module with parallel interface. This patch implement a v4l2 framework driver for it. Reviewed-by: Hans Verkuil Reviewed-by: Maxime Ripard Tested-by: Maxime Ripard Signed-off-by: Yong Deng --- MAINTAINERS| 8 + drivers/media/platform/Kconfig | 1 + drivers/media/platform/Makefile| 2 + drivers/media/platform/sunxi/sun6i-csi/Kconfig | 9 + drivers/media/platform/sunxi/sun6i-csi/Makefile| 3 + drivers/media/platform/sunxi/sun6i-csi/sun6i_csi.c | 915 + drivers/media/platform/sunxi/sun6i-csi/sun6i_csi.h | 135 +++ .../media/platform/sunxi/sun6i-csi/sun6i_csi_reg.h | 196 + .../media/platform/sunxi/sun6i-csi/sun6i_video.c | 678 +++ .../media/platform/sunxi/sun6i-csi/sun6i_video.h | 38 + 10 files changed, 1985 insertions(+) create mode 100644 drivers/media/platform/sunxi/sun6i-csi/Kconfig create mode 100644 drivers/media/platform/sunxi/sun6i-csi/Makefile create mode 100644 drivers/media/platform/sunxi/sun6i-csi/sun6i_csi.c create mode 100644 drivers/media/platform/sunxi/sun6i-csi/sun6i_csi.h create mode 100644 drivers/media/platform/sunxi/sun6i-csi/sun6i_csi_reg.h create mode 100644 drivers/media/platform/sunxi/sun6i-csi/sun6i_video.c create mode 100644 drivers/media/platform/sunxi/sun6i-csi/sun6i_video.h diff --git a/MAINTAINERS b/MAINTAINERS index 23021e0df5d7..42d73b35ed3e 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -3900,6 +3900,14 @@ M: Jaya Kumar S: Maintained F: sound/pci/cs5535audio/ +CSI DRIVERS FOR ALLWINNER V3s +M: Yong Deng +L: linux-media@vger.kernel.org +T: git git://linuxtv.org/media_tree.git +S: Maintained +F: drivers/media/platform/sunxi/sun6i-csi/ +F: Documentation/devicetree/bindings/media/sun6i-csi.txt + CW1200 WLAN driver M: Solomon Peachy S: Maintained diff --git a/drivers/media/platform/Kconfig b/drivers/media/platform/Kconfig index 0edacfb01f3a..be6626ed0ec8 100644 --- a/drivers/media/platform/Kconfig +++ b/drivers/media/platform/Kconfig @@ -138,6 +138,7 @@ source "drivers/media/platform/am437x/Kconfig" source "drivers/media/platform/xilinx/Kconfig" source "drivers/media/platform/rcar-vin/Kconfig" source "drivers/media/platform/atmel/Kconfig" +source "drivers/media/platform/sunxi/sun6i-csi/Kconfig" config VIDEO_TI_CAL tristate "TI CAL (Camera Adaptation Layer) driver" diff --git a/drivers/media/platform/Makefile b/drivers/media/platform/Makefile index 6ab6200dd9c9..2662a230f681 100644 --- a/drivers/media/platform/Makefile +++ b/drivers/media/platform/Makefile @@ -98,3 +98,5 @@ obj-$(CONFIG_VIDEO_QCOM_VENUS)+= qcom/venus/ obj-y += meson/ obj-y += cros-ec-cec/ + +obj-$(CONFIG_VIDEO_SUN6I_CSI) += sunxi/sun6i-csi/ diff --git a/drivers/media/platform/sunxi/sun6i-csi/Kconfig b/drivers/media/platform/sunxi/sun6i-csi/Kconfig new file mode 100644 index ..018e3ec788c0 --- /dev/null +++ b/drivers/media/platform/sunxi/sun6i-csi/Kconfig @@ -0,0 +1,9 @@ +config VIDEO_SUN6I_CSI + tristate "Allwinner V3s Camera Sensor Interface driver" + depends on VIDEO_V4L2 && COMMON_CLK && VIDEO_V4L2_SUBDEV_API && HAS_DMA + depends on ARCH_SUNXI || COMPILE_TEST + select VIDEOBUF2_DMA_CONTIG + select REGMAP_MMIO + select V4L2_FWNODE + help + Support for the Allwinner Camera Sensor Interface Controller on V3s. diff --git a/drivers/media/platform/sunxi/sun6i-csi/Makefile b/drivers/media/platform/sunxi/sun6i-csi/Makefile new file mode 100644 index ..213cb6be9e9c --- /dev/null +++ b/drivers/media/platform/sunxi/sun6i-csi/Makefile @@ -0,0 +1,3 @@ +sun6i-csi-y += sun6i_video.o sun6i_csi.o + +obj-$(CONFIG_VIDEO_SUN6I_CSI) += sun6i-csi.o diff --git a/drivers/media/platform/sunxi/sun6i-csi/sun6i_csi.c b/drivers/media/platform/sunxi/sun6i-csi/sun6i_csi.c new file mode 100644 index ..ff20e907aa84 --- /dev/null +++ b/drivers/media/platform/sunxi/sun6i-csi/sun6i_csi.c @@ -0,0 +1,915 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (c) 2011-2018 Magewell Electronics Co., Ltd. (Nanjing) + * All rights reserved. + * Author: Yong Deng + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "sun6i_csi.h" +#include "sun6i_csi_reg.h" + +#define MODULE_NAME"sun6i-csi" + +struct sun6i_csi_dev { + struct sun6i_csicsi; + struct device *dev; + + struct regmap *regmap; + struct clk *clk_mod; + struct clk
[PATCH v12 1/2] dt-bindings: media: Add Allwinner V3s Camera Sensor Interface (CSI)
Add binding documentation for Allwinner V3s CSI. Acked-by: Maxime Ripard Acked-by: Sakari Ailus Reviewed-by: Rob Herring Signed-off-by: Yong Deng --- .../devicetree/bindings/media/sun6i-csi.txt| 56 ++ 1 file changed, 56 insertions(+) create mode 100644 Documentation/devicetree/bindings/media/sun6i-csi.txt diff --git a/Documentation/devicetree/bindings/media/sun6i-csi.txt b/Documentation/devicetree/bindings/media/sun6i-csi.txt new file mode 100644 index ..443e18c181b3 --- /dev/null +++ b/Documentation/devicetree/bindings/media/sun6i-csi.txt @@ -0,0 +1,56 @@ +Allwinner V3s Camera Sensor Interface +- + +Allwinner V3s SoC features a CSI module(CSI1) with parallel interface. + +Required properties: + - compatible: value must be "allwinner,sun8i-v3s-csi" + - reg: base address and size of the memory-mapped region. + - interrupts: interrupt associated to this IP + - clocks: phandles to the clocks feeding the CSI +* bus: the CSI interface clock +* mod: the CSI module clock +* ram: the CSI DRAM clock + - clock-names: the clock names mentioned above + - resets: phandles to the reset line driving the CSI + +The CSI node should contain one 'port' child node with one child 'endpoint' +node, according to the bindings defined in +Documentation/devicetree/bindings/media/video-interfaces.txt. + +Endpoint node properties for CSI +- +See the video-interfaces.txt for a detailed description of these properties. +- remote-endpoint : (required) a phandle to the bus receiver's endpoint + node +- bus-width: : (required) must be 8, 10, 12 or 16 +- pclk-sample : (optional) (default: sample on falling edge) +- hsync-active : (required; parallel-only) +- vsync-active : (required; parallel-only) + +Example: + +csi1: csi@1cb4000 { + compatible = "allwinner,sun8i-v3s-csi"; + reg = <0x01cb4000 0x1000>; + interrupts = ; + clocks = <&ccu CLK_BUS_CSI>, +<&ccu CLK_CSI1_SCLK>, +<&ccu CLK_DRAM_CSI>; + clock-names = "bus", "mod", "ram"; + resets = <&ccu RST_BUS_CSI>; + + port { + /* Parallel bus endpoint */ + csi1_ep: endpoint { + remote-endpoint = <&adv7611_ep>; + bus-width = <16>; + + /* If hsync-active/vsync-active are missing, + embedded BT.656 sync is used */ + hsync-active = <0>; /* Active low */ + vsync-active = <0>; /* Active low */ + pclk-sample = <1>; /* Rising */ + }; + }; +}; -- 1.8.3.1
[PATCH v12 0/2] Initial Allwinner V3s CSI Support
terface Info: ID : 0x0303 Type : V4L Video Entity Info: ID : 0x0001 (1) Name : sun6i-csi Function : V4L2 I/O Pad 0x0102 : Sink, Must Connect Link 0x0207: from remote pad 0x106 of entity 'adv7611 0-004c': Data, Enabled, Immutable Required ioctls: test MC information (see 'Media Driver Info' above): OK test VIDIOC_QUERYCAP: OK Allow for multiple opens: test second /dev/video0 open: OK test VIDIOC_QUERYCAP: OK test VIDIOC_G/S_PRIORITY: OK test for unlimited opens: OK Debug ioctls: test VIDIOC_DBG_G/S_REGISTER: OK (Not Supported) test VIDIOC_LOG_STATUS: OK Input ioctls: test VIDIOC_G/S_TUNER/ENUM_FREQ_BANDS: OK (Not Supported) test VIDIOC_G/S_FREQUENCY: OK (Not Supported) test VIDIOC_S_HW_FREQ_SEEK: OK (Not Supported) test VIDIOC_ENUMAUDIO: OK (Not Supported) test VIDIOC_G/S/ENUMINPUT: OK test VIDIOC_G/S_AUDIO: OK (Not Supported) Inputs: 1 Audio Inputs: 0 Tuners: 0 Output ioctls: test VIDIOC_G/S_MODULATOR: OK (Not Supported) test VIDIOC_G/S_FREQUENCY: OK (Not Supported) test VIDIOC_ENUMAUDOUT: OK (Not Supported) test VIDIOC_G/S/ENUMOUTPUT: OK (Not Supported) test VIDIOC_G/S_AUDOUT: OK (Not Supported) Outputs: 0 Audio Outputs: 0 Modulators: 0 Input/Output configuration ioctls: test VIDIOC_ENUM/G/S/QUERY_STD: OK (Not Supported) test VIDIOC_ENUM/G/S/QUERY_DV_TIMINGS: OK (Not Supported) test VIDIOC_DV_TIMINGS_CAP: OK (Not Supported) test VIDIOC_G/S_EDID: OK (Not Supported) Control ioctls (Input 0): test VIDIOC_QUERY_EXT_CTRL/QUERYMENU: OK test VIDIOC_QUERYCTRL: OK test VIDIOC_G/S_CTRL: OK test VIDIOC_G/S/TRY_EXT_CTRLS: OK test VIDIOC_(UN)SUBSCRIBE_EVENT/DQEVENT: OK (Not Supported) test VIDIOC_G/S_JPEGCOMP: OK (Not Supported) Standard Controls: 0 Private Controls: 0 Format ioctls (Input 0): test VIDIOC_ENUM_FMT/FRAMESIZES/FRAMEINTERVALS: OK test VIDIOC_G/S_PARM: OK (Not Supported) test VIDIOC_G_FBUF: OK (Not Supported) test VIDIOC_G_FMT: OK test VIDIOC_TRY_FMT: OK test VIDIOC_S_FMT: OK test VIDIOC_G_SLICED_VBI_CAP: OK (Not Supported) test Cropping: OK (Not Supported) test Composing: OK (Not Supported) test Scaling: OK Codec ioctls (Input 0): test VIDIOC_(TRY_)ENCODER_CMD: OK (Not Supported) test VIDIOC_G_ENC_INDEX: OK (Not Supported) test VIDIOC_(TRY_)DECODER_CMD: OK (Not Supported) Buffer ioctls (Input 0): test VIDIOC_REQBUFS/CREATE_BUFS/QUERYBUF: OK test VIDIOC_EXPBUF: OK Test input 0: Streaming ioctls: test read/write: OK (Not Supported) test blocking wait: OK fail: v4l2-test-buffers.cpp(946): node->streamon(q.g_type()) test MMAP: FAIL test USERPTR: OK (Not Supported) test DMABUF: Cannot test, specify --expbuf-device Total: 48, Succeeded: 47, Failed: 1, Warnings: 0 Yong Deng (2): dt-bindings: media: Add Allwinner V3s Camera Sensor Interface (CSI) media: V3s: Add support for Allwinner CSI. .../devicetree/bindings/media/sun6i-csi.txt| 56 ++ MAINTAINERS| 8 + drivers/media/platform/Kconfig | 1 + drivers/media/platform/Makefile| 2 + drivers/media/platform/sunxi/sun6i-csi/Kconfig | 9 + drivers/media/platform/sunxi/sun6i-csi/Makefile| 3 + drivers/media/platform/sunxi/sun6i-csi/sun6i_csi.c | 915 + drivers/media/platform/sunxi/sun6i-csi/sun6i_csi.h | 135 +++ .../media/platform/sunxi/sun6i-csi/sun6i_csi_reg.h | 196 + .../media/platform/sunxi/sun6i-csi/sun6i_video.c | 678 +++ .../media/platform/sunxi/sun6i-csi/sun6i_video.h | 38 + 11 files changed, 2041 insertions(+) create mode 100644 Documentation/devicetree/bindings/media/sun6i-csi.txt create mode 100644 drivers/media/platform/sunxi/sun6i-csi/Kconfig create mode 100644 drivers/media/platform/sunxi/sun6i-csi/Makefile create mode 100644 drivers/media/platform/sunxi/sun6i-csi/sun6i_csi.c create mode 100644 drivers/media/platform/sunxi/sun6i-csi/sun6i_csi.h create mode 100644 drivers/media/platform/sunxi/sun6i-csi/sun6i_csi_reg.h create mode 100644 drivers/media/platform/sunxi/sun6i-csi/sun6i_video.c create mode 100644 drivers/media/platform/sunxi/sun6i-csi/sun6i_video.h -- 1.8.3.1
[PATCH v7 09/16] intel-ipu3: css: Add support for firmware management
Introduce functions to load and install ImgU FW blobs. Signed-off-by: Yong Zhi --- drivers/media/pci/intel/ipu3/ipu3-css-fw.c | 264 + drivers/media/pci/intel/ipu3/ipu3-css-fw.h | 188 2 files changed, 452 insertions(+) create mode 100644 drivers/media/pci/intel/ipu3/ipu3-css-fw.c create mode 100644 drivers/media/pci/intel/ipu3/ipu3-css-fw.h diff --git a/drivers/media/pci/intel/ipu3/ipu3-css-fw.c b/drivers/media/pci/intel/ipu3/ipu3-css-fw.c new file mode 100644 index 000..ba459e9 --- /dev/null +++ b/drivers/media/pci/intel/ipu3/ipu3-css-fw.c @@ -0,0 +1,264 @@ +// SPDX-License-Identifier: GPL-2.0 +// Copyright (C) 2018 Intel Corporation + +#include +#include +#include +#include + +#include "ipu3-css.h" +#include "ipu3-css-fw.h" +#include "ipu3-dmamap.h" + +static void ipu3_css_fw_show_binary(struct device *dev, struct imgu_fw_info *bi, + const char *name) +{ + unsigned int i; + + dev_dbg(dev, "found firmware binary type %i size %i name %s\n", + bi->type, bi->blob.size, name); + if (bi->type != IMGU_FW_ISP_FIRMWARE) + return; + + dev_dbg(dev, "id %i mode %i bds 0x%x veceven %i/%i out_pins %i\n", + bi->info.isp.sp.id, bi->info.isp.sp.pipeline.mode, + bi->info.isp.sp.bds.supported_bds_factors, + bi->info.isp.sp.enable.vf_veceven, + bi->info.isp.sp.vf_dec.is_variable, + bi->info.isp.num_output_pins); + + dev_dbg(dev, "input (%i,%i)-(%i,%i) formats %s%s%s\n", + bi->info.isp.sp.input.min_width, + bi->info.isp.sp.input.min_height, + bi->info.isp.sp.input.max_width, + bi->info.isp.sp.input.max_height, + bi->info.isp.sp.enable.input_yuv ? "yuv420 " : "", + bi->info.isp.sp.enable.input_feeder || + bi->info.isp.sp.enable.input_raw ? "raw8 raw10 " : "", + bi->info.isp.sp.enable.input_raw ? "raw12" : ""); + + dev_dbg(dev, "internal (%i,%i)\n", + bi->info.isp.sp.internal.max_width, + bi->info.isp.sp.internal.max_height); + + dev_dbg(dev, "output (%i,%i)-(%i,%i) formats", + bi->info.isp.sp.output.min_width, + bi->info.isp.sp.output.min_height, + bi->info.isp.sp.output.max_width, + bi->info.isp.sp.output.max_height); + for (i = 0; i < bi->info.isp.num_output_formats; i++) + dev_dbg(dev, " %i", bi->info.isp.output_formats[i]); + dev_dbg(dev, " vf"); + for (i = 0; i < bi->info.isp.num_vf_formats; i++) + dev_dbg(dev, " %i", bi->info.isp.vf_formats[i]); + dev_dbg(dev, "\n"); +} + +unsigned int ipu3_css_fw_obgrid_size(const struct imgu_fw_info *bi) +{ + unsigned int width = DIV_ROUND_UP(bi->info.isp.sp.internal.max_width, + IMGU_OBGRID_TILE_SIZE * 2) + 1; + unsigned int height = DIV_ROUND_UP(bi->info.isp.sp.internal.max_height, + IMGU_OBGRID_TILE_SIZE * 2) + 1; + unsigned int obgrid_size; + + width = ALIGN(width, IPU3_UAPI_ISP_VEC_ELEMS / 4); + obgrid_size = PAGE_ALIGN(width * height * +sizeof(struct ipu3_uapi_obgrid_param)) * +bi->info.isp.sp.iterator.num_stripes; + return obgrid_size; +} + +void *ipu3_css_fw_pipeline_params(struct ipu3_css *css, + enum imgu_abi_param_class c, + enum imgu_abi_memories m, + struct imgu_fw_isp_parameter *par, + size_t par_size, void *binary_params) +{ + struct imgu_fw_info *bi = &css->fwp->binary_header[css->current_binary]; + + if (par->offset + par->size > + bi->info.isp.sp.mem_initializers.params[c][m].size) + return NULL; + + if (par->size != par_size) + pr_warn("parameter size doesn't match defined size\n"); + + if (par->size < par_size) + return NULL; + + return binary_params + par->offset; +} + +void ipu3_css_fw_cleanup(struct ipu3_css *css) +{ + struct imgu_device *imgu = dev_get_drvdata(css->dev); + + if (css->binary) { + unsigned int i; + + for (i = 0; i < css->fwp->file_header.binary_nr; i++) + ipu3_dmamap_free(imgu, &css->binary[i]); + kfree(css->binary); + } + if (c
[PATCH v7 15/16] intel-ipu3: Add imgu top level pci device driver
This patch adds support for the Intel IPU v3 as found on Skylake and Kaby Lake SoCs. The driver glues v4l2, css(camera sub system) and other pieces together to perform its functions, it also loads the IPU3 firmware binary as part of its initialization. Signed-off-by: Yong Zhi Signed-off-by: Tomasz Figa --- drivers/media/pci/intel/ipu3/Kconfig | 16 + drivers/media/pci/intel/ipu3/Makefile | 12 + drivers/media/pci/intel/ipu3/ipu3.c | 844 ++ drivers/media/pci/intel/ipu3/ipu3.h | 153 ++ 4 files changed, 1025 insertions(+) create mode 100644 drivers/media/pci/intel/ipu3/ipu3.c create mode 100644 drivers/media/pci/intel/ipu3/ipu3.h diff --git a/drivers/media/pci/intel/ipu3/Kconfig b/drivers/media/pci/intel/ipu3/Kconfig index 715f776..44ebcbb 100644 --- a/drivers/media/pci/intel/ipu3/Kconfig +++ b/drivers/media/pci/intel/ipu3/Kconfig @@ -15,3 +15,19 @@ config VIDEO_IPU3_CIO2 Say Y or M here if you have a Skylake/Kaby Lake SoC with MIPI CSI-2 connected camera. The module will be called ipu3-cio2. + +config VIDEO_IPU3_IMGU + tristate "Intel ipu3-imgu driver" + depends on PCI && VIDEO_V4L2 + depends on MEDIA_CONTROLLER && VIDEO_V4L2_SUBDEV_API + depends on X86 + select IOMMU_IOVA + select VIDEOBUF2_DMA_SG + + ---help--- + This is the video4linux2 driver for Intel IPU3 image processing unit, + found in Intel Skylake and Kaby Lake SoCs and used for processing + images and video. + + Say Y or M here if you have a Skylake/Kaby Lake SoC with a MIPI + camera. The module will be called ipu3-imgu. diff --git a/drivers/media/pci/intel/ipu3/Makefile b/drivers/media/pci/intel/ipu3/Makefile index 20186e3..60bd5db 100644 --- a/drivers/media/pci/intel/ipu3/Makefile +++ b/drivers/media/pci/intel/ipu3/Makefile @@ -1 +1,13 @@ +# +# Makefile for the IPU3 cio2 and ImgU drivers +# + obj-$(CONFIG_VIDEO_IPU3_CIO2) += ipu3-cio2.o + +ipu3-imgu-objs += \ + ipu3-mmu.o ipu3-dmamap.o \ + ipu3-tables.o ipu3-css-pool.o \ + ipu3-css-fw.o ipu3-css-params.o \ + ipu3-css.o ipu3-v4l2.o ipu3.o + +obj-$(CONFIG_VIDEO_IPU3_IMGU) += ipu3-imgu.o diff --git a/drivers/media/pci/intel/ipu3/ipu3.c b/drivers/media/pci/intel/ipu3/ipu3.c new file mode 100644 index 000..eda7299 --- /dev/null +++ b/drivers/media/pci/intel/ipu3/ipu3.c @@ -0,0 +1,844 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (C) 2017 Intel Corporation + * Copyright 2017 Google LLC + * + * Based on Intel IPU4 driver. + * + */ + +#include +#include +#include +#include + +#include "ipu3.h" +#include "ipu3-dmamap.h" +#include "ipu3-mmu.h" + +#define IMGU_PCI_ID0x1919 +#define IMGU_PCI_BAR 0 +#define IMGU_DMA_MASK DMA_BIT_MASK(39) +#define IMGU_MAX_QUEUE_DEPTH (2 + 2) + +/* + * pre-allocated buffer size for IMGU dummy buffers. Those + * values should be tuned to big enough to avoid buffer + * re-allocation when streaming to lower streaming latency. + */ +#define CSS_QUEUE_IN_BUF_SIZE 0 +#define CSS_QUEUE_PARAMS_BUF_SIZE 0 +#define CSS_QUEUE_OUT_BUF_SIZE (4160 * 3120 * 12 / 8) +#define CSS_QUEUE_VF_BUF_SIZE (1920 * 1080 * 12 / 8) +#define CSS_QUEUE_STAT_3A_BUF_SIZE 125664 + +static const size_t css_queue_buf_size_map[IPU3_CSS_QUEUES] = { + [IPU3_CSS_QUEUE_IN] = CSS_QUEUE_IN_BUF_SIZE, + [IPU3_CSS_QUEUE_PARAMS] = CSS_QUEUE_PARAMS_BUF_SIZE, + [IPU3_CSS_QUEUE_OUT] = CSS_QUEUE_OUT_BUF_SIZE, + [IPU3_CSS_QUEUE_VF] = CSS_QUEUE_VF_BUF_SIZE, + [IPU3_CSS_QUEUE_STAT_3A] = CSS_QUEUE_STAT_3A_BUF_SIZE, +}; + +static const struct imgu_node_mapping imgu_node_map[IMGU_NODE_NUM] = { + [IMGU_NODE_IN] = {IPU3_CSS_QUEUE_IN, "input"}, + [IMGU_NODE_PARAMS] = {IPU3_CSS_QUEUE_PARAMS, "parameters"}, + [IMGU_NODE_OUT] = {IPU3_CSS_QUEUE_OUT, "output"}, + [IMGU_NODE_VF] = {IPU3_CSS_QUEUE_VF, "viewfinder"}, + [IMGU_NODE_PV] = {IPU3_CSS_QUEUE_VF, "postview"}, + [IMGU_NODE_STAT_3A] = {IPU3_CSS_QUEUE_STAT_3A, "3a stat"}, +}; + +unsigned int imgu_node_to_queue(unsigned int node) +{ + return imgu_node_map[node].css_queue; +} + +unsigned int imgu_map_node(struct imgu_device *imgu, unsigned int css_queue) +{ + unsigned int i; + + if (css_queue == IPU3_CSS_QUEUE_VF) + return imgu->nodes[IMGU_NODE_VF].enabled ? + IMGU_NODE_VF : IMGU_NODE_PV; + + for (i = 0; i < IMGU_NODE_NUM; i++) + if (imgu_node_map[i].css_queue == css_queue) + break; + + return i; +} + +/ Dummy buffers / + +static void imgu_dummybufs_cleanup(struct imgu_device *imgu) +{ + unsigned int i; + +
[PATCH v7 01/16] v4l: Add Intel IPU3 meta buffer formats
Add IPU3-specific meta formats for parameter processing and 3A, DVS statistics: V4L2_META_FMT_IPU3_PARAMS V4L2_META_FMT_IPU3_STAT_3A Signed-off-by: Yong Zhi --- drivers/media/v4l2-core/v4l2-ioctl.c | 2 ++ include/uapi/linux/videodev2.h | 4 2 files changed, 6 insertions(+) diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c index 6489f25..abff64b 100644 --- a/drivers/media/v4l2-core/v4l2-ioctl.c +++ b/drivers/media/v4l2-core/v4l2-ioctl.c @@ -1299,6 +1299,8 @@ static void v4l_fill_fmtdesc(struct v4l2_fmtdesc *fmt) case V4L2_META_FMT_VSP1_HGO:descr = "R-Car VSP1 1-D Histogram"; break; case V4L2_META_FMT_VSP1_HGT:descr = "R-Car VSP1 2-D Histogram"; break; case V4L2_META_FMT_UVC: descr = "UVC payload header metadata"; break; + case V4L2_META_FMT_IPU3_PARAMS: descr = "IPU3 processing parameters"; break; + case V4L2_META_FMT_IPU3_STAT_3A:descr = "IPU3 3A statistics"; break; default: /* Compressed formats */ diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h index f0a968a..bdccd7a 100644 --- a/include/uapi/linux/videodev2.h +++ b/include/uapi/linux/videodev2.h @@ -718,6 +718,10 @@ struct v4l2_pix_format { #define V4L2_META_FMT_UVC v4l2_fourcc('U', 'V', 'C', 'H') /* UVC Payload Header metadata */ #define V4L2_META_FMT_D4XXv4l2_fourcc('D', '4', 'X', 'X') /* D4XX Payload Header metadata */ +/* Vendor specific - used for IPU3 camera sub-system */ +#define V4L2_META_FMT_IPU3_PARAMS v4l2_fourcc('i', 'p', '3', 'p') /* IPU3 params */ +#define V4L2_META_FMT_IPU3_STAT_3A v4l2_fourcc('i', 'p', '3', 's') /* IPU3 3A statistics */ + /* priv field value to indicates that subsequent fields are valid. */ #define V4L2_PIX_FMT_PRIV_MAGIC0xfeedcafe -- 2.7.4
[PATCH v7 05/16] intel-ipu3: abi: Add structs
This add all the structs of IPU3 firmware ABI. Signed-off-by: Yong Zhi Signed-off-by: Rajmohan Mani --- drivers/media/pci/intel/ipu3/ipu3-abi.h | 1350 +++ 1 file changed, 1350 insertions(+) diff --git a/drivers/media/pci/intel/ipu3/ipu3-abi.h b/drivers/media/pci/intel/ipu3/ipu3-abi.h index ac08ad3..21703da 100644 --- a/drivers/media/pci/intel/ipu3/ipu3-abi.h +++ b/drivers/media/pci/intel/ipu3/ipu3-abi.h @@ -658,4 +658,1354 @@ enum imgu_abi_stage_type { IMGU_ABI_STAGE_TYPE_ISP, }; +struct imgu_abi_acc_operation { + /* +* zero means on init, +* others mean upon receiving an ack signal from the BC acc. +*/ + u8 op_indicator; + u8 op_type; +} __packed; + +struct imgu_abi_acc_process_lines_cmd_data { + u16 lines; + u8 cfg_set; + u8 __reserved; /* Align to 4 bytes */ +} __packed; + +/* Bayer shading definitions */ + +struct imgu_abi_shd_transfer_luts_set_data { + u8 set_number; + u8 padding[3]; + imgu_addr_t rg_lut_ddr_addr; + imgu_addr_t bg_lut_ddr_addr; + u32 align_dummy; +} __packed; + +struct imgu_abi_shd_grid_config { + /* reg 0 */ + u32 grid_width:8; + u32 grid_height:8; + u32 block_width:3; + u32 __reserved0:1; + u32 block_height:3; + u32 __reserved1:1; + u32 grid_height_per_slice:8; + /* reg 1 */ + s32 x_start:13; + s32 __reserved2:3; + s32 y_start:13; + s32 __reserved3:3; +} __packed; + +struct imgu_abi_shd_general_config { + u32 init_set_vrt_offst_ul:8; + u32 shd_enable:1; + /* aka 'gf' */ + u32 gain_factor:2; + u32 __reserved:21; +} __packed; + +struct imgu_abi_shd_black_level_config { + /* reg 0 */ + s32 bl_r:12; + s32 __reserved0:4; + s32 bl_gr:12; + u32 __reserved1:1; + /* aka 'nf' */ + u32 normalization_shift:3; + /* reg 1 */ + s32 bl_gb:12; + s32 __reserved2:4; + s32 bl_b:12; + s32 __reserved3:4; +} __packed; + +struct imgu_abi_shd_intra_frame_operations_data { + struct imgu_abi_acc_operation + operation_list[IMGU_ABI_SHD_MAX_OPERATIONS] __attribute__((aligned(32))); + struct imgu_abi_acc_process_lines_cmd_data + process_lines_data[IMGU_ABI_SHD_MAX_PROCESS_LINES] __attribute__((aligned(32))); + struct imgu_abi_shd_transfer_luts_set_data + transfer_data[IMGU_ABI_SHD_MAX_TRANSFERS] __attribute__((aligned(32))); +} __packed; + +struct imgu_abi_shd_config { + struct ipu3_uapi_shd_config_static shd __attribute__((aligned(32))); + struct imgu_abi_shd_intra_frame_operations_data shd_ops __attribute__((aligned(32))); + struct ipu3_uapi_shd_lut shd_lut __attribute__((aligned(32))); +} __packed; + +struct imgu_abi_stripe_input_frame_resolution { + u16 width; + u16 height; + u32 bayer_order;/* enum ipu3_uapi_bayer_order */ + u32 raw_bit_depth; +} __packed; + +/* Stripe-based processing */ + +struct imgu_abi_stripes { + /* offset from start of frame - measured in pixels */ + u16 offset; + /* stripe width - measured in pixels */ + u16 width; + /* stripe width - measured in pixels */ + u16 height; +} __packed; + +struct imgu_abi_stripe_data { + /* +* number of stripes for current processing source +* - VLIW binary parameter we currently support 1 or 2 stripes +*/ + u16 num_of_stripes; + + u8 padding[2]; + + /* +* the following data is derived from resolution-related +* pipe config and from num_of_stripes +*/ + + /* +*'input-stripes' - before input cropping +* used by input feeder +*/ + struct imgu_abi_stripe_input_frame_resolution input_frame; + + /*'effective-stripes' - after input cropping used dpc, bds */ + struct imgu_abi_stripes effective_stripes[IPU3_UAPI_MAX_STRIPES]; + + /* 'down-scaled-stripes' - after down-scaling ONLY. used by BDS */ + struct imgu_abi_stripes down_scaled_stripes[IPU3_UAPI_MAX_STRIPES]; + + /* +*'bds-out-stripes' - after bayer down-scaling and padding. +* used by all algos starting with norm up to the ref-frame for GDC +* (currently up to the output kernel) +*/ + struct imgu_abi_stripes bds_out_stripes[IPU3_UAPI_MAX_STRIPES]; + + /* 'bds-out-stripes (no overlap)' - used for ref kernel */ + struct imgu_abi_stripes + bds_out_stripes_no_overlap[IPU3_UAPI_MAX_STRIPES]; + + /* +* input resolution for output system (equal to bds_out - envelope) +* output-system input frame width as configured by user +*/ + u16 output_system_in_frame_width; + /* output-system input frame hei
[PATCH v7 08/16] intel-ipu3: css: Add dma buff pool utility functions
The pools are used to store previous parameters set by user with the parameter queue. Due to pipelining, there needs to be multiple sets (up to four) of parameters which are queued in a host-to-sp queue. Signed-off-by: Yong Zhi --- drivers/media/pci/intel/ipu3/ipu3-css-pool.c | 136 +++ drivers/media/pci/intel/ipu3/ipu3-css-pool.h | 56 +++ 2 files changed, 192 insertions(+) create mode 100644 drivers/media/pci/intel/ipu3/ipu3-css-pool.c create mode 100644 drivers/media/pci/intel/ipu3/ipu3-css-pool.h diff --git a/drivers/media/pci/intel/ipu3/ipu3-css-pool.c b/drivers/media/pci/intel/ipu3/ipu3-css-pool.c new file mode 100644 index 000..eab41c3 --- /dev/null +++ b/drivers/media/pci/intel/ipu3/ipu3-css-pool.c @@ -0,0 +1,136 @@ +// SPDX-License-Identifier: GPL-2.0 +// Copyright (C) 2018 Intel Corporation + +#include + +#include "ipu3.h" +#include "ipu3-css-pool.h" +#include "ipu3-dmamap.h" + +int ipu3_css_dma_buffer_resize(struct imgu_device *imgu, + struct ipu3_css_map *map, size_t size) +{ + if (map->size < size && map->vaddr) { + dev_warn(&imgu->pci_dev->dev, "dma buf resized from %zu to %zu", +map->size, size); + + ipu3_dmamap_free(imgu, map); + if (!ipu3_dmamap_alloc(imgu, map, size)) + return -ENOMEM; + } + + return 0; +} + +void ipu3_css_pool_cleanup(struct imgu_device *imgu, struct ipu3_css_pool *pool) +{ + unsigned int i; + + for (i = 0; i < IPU3_CSS_POOL_SIZE; i++) + ipu3_dmamap_free(imgu, &pool->entry[i].param); +} + +int ipu3_css_pool_init(struct imgu_device *imgu, struct ipu3_css_pool *pool, + size_t size) +{ + unsigned int i; + + for (i = 0; i < IPU3_CSS_POOL_SIZE; i++) { + /* +* entry[i].framenum is initialized to INT_MIN so that +* ipu3_css_pool_check() can treat it as usesable slot. +*/ + pool->entry[i].framenum = INT_MIN; + + if (size == 0) { + pool->entry[i].param.vaddr = NULL; + continue; + } + + if (!ipu3_dmamap_alloc(imgu, &pool->entry[i].param, size)) + goto fail; + } + + pool->last = IPU3_CSS_POOL_SIZE; + + return 0; + +fail: + ipu3_css_pool_cleanup(imgu, pool); + return -ENOMEM; +} + +/* + * Check that the following call to pool_get succeeds. + * Return negative on error. + */ +static int ipu3_css_pool_check(struct ipu3_css_pool *pool, long framenum) +{ + /* Get the oldest entry */ + int n = (pool->last + 1) % IPU3_CSS_POOL_SIZE; + long diff = framenum - pool->entry[n].framenum; + + /* if framenum wraps around and becomes smaller than entry n */ + if (diff < 0) + diff += LONG_MAX; + + /* +* pool->entry[n].framenum stores the frame number where that +* entry was allocated. If that was allocated more than POOL_SIZE +* frames back, it is old enough that we know it is no more in +* use by firmware. +*/ + if (diff > IPU3_CSS_POOL_SIZE) + return n; + + return -ENOSPC; +} + +/* + * Allocate a new parameter from pool at frame number `framenum'. + * Release the oldest entry in the pool to make space for the new entry. + * Return negative on error. + */ +int ipu3_css_pool_get(struct ipu3_css_pool *pool, long framenum) +{ + int n = ipu3_css_pool_check(pool, framenum); + + if (n < 0) + return n; + + pool->entry[n].framenum = framenum; + pool->last = n; + + return n; +} + +/* + * Undo, for all practical purposes, the effect of pool_get(). + */ +void ipu3_css_pool_put(struct ipu3_css_pool *pool) +{ + pool->entry[pool->last].framenum = INT_MIN; + pool->last = (pool->last + IPU3_CSS_POOL_SIZE - 1) % IPU3_CSS_POOL_SIZE; +} + +/** + * ipu3_css_pool_last - Retrieve the nth pool entry from last + * + * @pool: a pointer to &struct ipu3_css_pool. + * @n: the distance to the last index. + * + * Return: The nth entry from last or null map to indicate no frame stored. + */ +const struct ipu3_css_map * +ipu3_css_pool_last(struct ipu3_css_pool *pool, unsigned int n) +{ + static const struct ipu3_css_map null_map = { 0 }; + int i = (pool->last + IPU3_CSS_POOL_SIZE - n) % IPU3_CSS_POOL_SIZE; + + WARN_ON(n >= IPU3_CSS_POOL_SIZE); + + if (pool->entry[i].framenum < 0) + return &null_map; + + return &pool->entry[i].param; +} diff --git a/drivers/media/pci/intel/ipu3/ipu3-css-pool.h b/drivers/media/pci/intel/ipu3/ipu3-css-pool.h new file mode 100644 index 000..71e48d1 --- /dev/null +++ b/dri
[PATCH v7 13/16] intel-ipu3: Add css pipeline programming
This provides helper library to be used by v4l2 level to program imaging pipelines and control the streaming. Signed-off-by: Yong Zhi --- drivers/media/pci/intel/ipu3/ipu3-css.c | 1760 +++ 1 file changed, 1760 insertions(+) diff --git a/drivers/media/pci/intel/ipu3/ipu3-css.c b/drivers/media/pci/intel/ipu3/ipu3-css.c index 164830f..c63b387 100644 --- a/drivers/media/pci/intel/ipu3/ipu3-css.c +++ b/drivers/media/pci/intel/ipu3/ipu3-css.c @@ -16,6 +16,173 @@ IMGU_IRQCTRL_IRQ_SW_PIN(0) | \ IMGU_IRQCTRL_IRQ_SW_PIN(1)) +#define IPU3_CSS_FORMAT_BPP_DEN50 /* Denominator */ + +/* Some sane limits for resolutions */ +#define IPU3_CSS_MIN_RES 32 +#define IPU3_CSS_MAX_H 3136 +#define IPU3_CSS_MAX_W 4224 + +/* filter size from graph settings is fixed as 4 */ +#define FILTER_SIZE 4 +#define MIN_ENVELOPE8 + +/* + * pre-allocated buffer size for CSS ABI, auxiliary frames + * after BDS and before GDC. Those values should be tuned + * to big enough to avoid buffer re-allocation when + * streaming to lower streaming latency. + */ +#define CSS_ABI_SIZE136 +#define CSS_BDS_SIZE(4480 * 3200 * 3) +#define CSS_GDC_SIZE(4224 * 3200 * 12 / 8) + +#define IPU3_CSS_QUEUE_TO_FLAGS(q) (1 << (q)) +#define IPU3_CSS_FORMAT_FL_IN \ + IPU3_CSS_QUEUE_TO_FLAGS(IPU3_CSS_QUEUE_IN) +#define IPU3_CSS_FORMAT_FL_OUT \ + IPU3_CSS_QUEUE_TO_FLAGS(IPU3_CSS_QUEUE_OUT) +#define IPU3_CSS_FORMAT_FL_VF \ + IPU3_CSS_QUEUE_TO_FLAGS(IPU3_CSS_QUEUE_VF) + +/* Formats supported by IPU3 Camera Sub System */ +static const struct ipu3_css_format ipu3_css_formats[] = { + { + .pixelformat = V4L2_PIX_FMT_NV12, + .colorspace = V4L2_COLORSPACE_SRGB, + .frame_format = IMGU_ABI_FRAME_FORMAT_NV12, + .osys_format = IMGU_ABI_OSYS_FORMAT_NV12, + .osys_tiling = IMGU_ABI_OSYS_TILING_NONE, + .bytesperpixel_num = 1 * IPU3_CSS_FORMAT_BPP_DEN, + .chroma_decim = 4, + .width_align = IPU3_UAPI_ISP_VEC_ELEMS, + .flags = IPU3_CSS_FORMAT_FL_OUT | IPU3_CSS_FORMAT_FL_VF, + }, { + /* Each 32 bytes contains 25 10-bit pixels */ + .pixelformat = V4L2_PIX_FMT_IPU3_SBGGR10, + .colorspace = V4L2_COLORSPACE_RAW, + .frame_format = IMGU_ABI_FRAME_FORMAT_RAW_PACKED, + .bayer_order = IMGU_ABI_BAYER_ORDER_BGGR, + .bit_depth = 10, + .bytesperpixel_num = 64, + .width_align = 2 * IPU3_UAPI_ISP_VEC_ELEMS, + .flags = IPU3_CSS_FORMAT_FL_IN, + }, { + .pixelformat = V4L2_PIX_FMT_IPU3_SGBRG10, + .colorspace = V4L2_COLORSPACE_RAW, + .frame_format = IMGU_ABI_FRAME_FORMAT_RAW_PACKED, + .bayer_order = IMGU_ABI_BAYER_ORDER_GBRG, + .bit_depth = 10, + .bytesperpixel_num = 64, + .width_align = 2 * IPU3_UAPI_ISP_VEC_ELEMS, + .flags = IPU3_CSS_FORMAT_FL_IN, + }, { + .pixelformat = V4L2_PIX_FMT_IPU3_SGRBG10, + .colorspace = V4L2_COLORSPACE_RAW, + .frame_format = IMGU_ABI_FRAME_FORMAT_RAW_PACKED, + .bayer_order = IMGU_ABI_BAYER_ORDER_GRBG, + .bit_depth = 10, + .bytesperpixel_num = 64, + .width_align = 2 * IPU3_UAPI_ISP_VEC_ELEMS, + .flags = IPU3_CSS_FORMAT_FL_IN, + }, { + .pixelformat = V4L2_PIX_FMT_IPU3_SRGGB10, + .colorspace = V4L2_COLORSPACE_RAW, + .frame_format = IMGU_ABI_FRAME_FORMAT_RAW_PACKED, + .bayer_order = IMGU_ABI_BAYER_ORDER_RGGB, + .bit_depth = 10, + .bytesperpixel_num = 64, + .width_align = 2 * IPU3_UAPI_ISP_VEC_ELEMS, + .flags = IPU3_CSS_FORMAT_FL_IN, + }, +}; + +static const struct { + enum imgu_abi_queue_id qid; + size_t ptr_ofs; +} ipu3_css_queues[IPU3_CSS_QUEUES] = { + [IPU3_CSS_QUEUE_IN] = { + IMGU_ABI_QUEUE_C_ID, + offsetof(struct imgu_abi_buffer, payload.frame.frame_data) + }, + [IPU3_CSS_QUEUE_OUT] = { + IMGU_ABI_QUEUE_D_ID, + offsetof(struct imgu_abi_buffer, payload.frame.frame_data) + }, + [IPU3_CSS_QUEUE_VF] = { + IMGU_ABI_QUEUE_E_ID, + offsetof(struct imgu_abi_buffer, payload.frame.frame_data) + }, + [IPU3_CSS_QUEUE_STAT_3A] = { + IMGU_ABI_QUEUE_F_ID, + offsetof(struct imgu_abi_buffer, payload.s3a.data_ptr) + }, +}; + +/* Initialize queue based on given format, adjust format as needed */ +static int ipu3_css_queue_init(struct ipu3_css_queue
[PATCH v7 14/16] intel-ipu3: Add v4l2 driver based on media framework
Implement video driver that utilizes v4l2, vb2 queue support and media controller APIs. The driver exposes single subdevice and six nodes. Signed-off-by: Yong Zhi --- drivers/media/pci/intel/ipu3/ipu3-v4l2.c | 1091 ++ 1 file changed, 1091 insertions(+) create mode 100644 drivers/media/pci/intel/ipu3/ipu3-v4l2.c diff --git a/drivers/media/pci/intel/ipu3/ipu3-v4l2.c b/drivers/media/pci/intel/ipu3/ipu3-v4l2.c new file mode 100644 index 000..31a3514 --- /dev/null +++ b/drivers/media/pci/intel/ipu3/ipu3-v4l2.c @@ -0,0 +1,1091 @@ +// SPDX-License-Identifier: GPL-2.0 +// Copyright (C) 2018 Intel Corporation + +#include +#include + +#include + +#include "ipu3.h" +#include "ipu3-dmamap.h" + +/ v4l2_subdev_ops / + +static int ipu3_subdev_open(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh) +{ + struct imgu_device *imgu = container_of(sd, struct imgu_device, subdev); + struct v4l2_rect try_crop = { + .top = 0, + .left = 0, + .height = imgu->nodes[IMGU_NODE_IN].vdev_fmt.fmt.pix_mp.height, + .width = imgu->nodes[IMGU_NODE_IN].vdev_fmt.fmt.pix_mp.width, + }; + unsigned int i; + + /* Initialize try_fmt */ + for (i = 0; i < IMGU_NODE_NUM; i++) + *v4l2_subdev_get_try_format(sd, fh->pad, i) = + imgu->nodes[i].pad_fmt; + + *v4l2_subdev_get_try_crop(sd, fh->pad, IMGU_NODE_IN) = try_crop; + + return 0; +} + +static int ipu3_subdev_s_stream(struct v4l2_subdev *sd, int enable) +{ + struct imgu_device *imgu = container_of(sd, struct imgu_device, subdev); + int r = 0; + + r = imgu_s_stream(imgu, enable); + if (!r) + imgu->streaming = enable; + + return r; +} + +static int ipu3_subdev_get_fmt(struct v4l2_subdev *sd, + struct v4l2_subdev_pad_config *cfg, + struct v4l2_subdev_format *fmt) +{ + struct imgu_device *imgu = container_of(sd, struct imgu_device, subdev); + struct v4l2_mbus_framefmt *mf; + u32 pad = fmt->pad; + + if (fmt->which == V4L2_SUBDEV_FORMAT_ACTIVE) { + fmt->format = imgu->nodes[pad].pad_fmt; + } else { + mf = v4l2_subdev_get_try_format(sd, cfg, pad); + fmt->format = *mf; + } + + return 0; +} + +static int ipu3_subdev_set_fmt(struct v4l2_subdev *sd, + struct v4l2_subdev_pad_config *cfg, + struct v4l2_subdev_format *fmt) +{ + struct imgu_device *imgu = container_of(sd, struct imgu_device, subdev); + struct v4l2_mbus_framefmt *mf; + u32 pad = fmt->pad; + + if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) + mf = v4l2_subdev_get_try_format(sd, cfg, pad); + else + mf = &imgu->nodes[pad].pad_fmt; + + fmt->format.code = mf->code; + /* Clamp the w and h based on the hardware capabilities */ + if (imgu->subdev_pads[pad].flags & MEDIA_PAD_FL_SOURCE) { + fmt->format.width = clamp(fmt->format.width, + IPU3_OUTPUT_MIN_WIDTH, + IPU3_OUTPUT_MAX_WIDTH); + fmt->format.height = clamp(fmt->format.height, + IPU3_OUTPUT_MIN_HEIGHT, + IPU3_OUTPUT_MAX_HEIGHT); + } else { + fmt->format.width = clamp(fmt->format.width, + IPU3_INPUT_MIN_WIDTH, + IPU3_INPUT_MAX_WIDTH); + fmt->format.height = clamp(fmt->format.height, + IPU3_INPUT_MIN_HEIGHT, + IPU3_INPUT_MAX_HEIGHT); + } + + *mf = fmt->format; + + return 0; +} + +static int ipu3_subdev_get_selection(struct v4l2_subdev *sd, +struct v4l2_subdev_pad_config *cfg, +struct v4l2_subdev_selection *sel) +{ + struct imgu_device *imgu = container_of(sd, struct imgu_device, subdev); + struct v4l2_rect *try_sel, *r; + + if (sel->pad != IMGU_NODE_IN) + return -EINVAL; + + switch (sel->target) { + case V4L2_SEL_TGT_CROP: + try_sel = v4l2_subdev_get_try_crop(sd, cfg, sel->pad); + r = &imgu->rect.eff; + break; + case V4L2_SEL_TGT_COMPOSE: + try_sel = v4l2_subdev_get_try_compose(sd, cfg, sel->pad); + r = &imgu->rect.bds; + break; + default: + return -EINVAL; + } + + if (sel->which == V4L2_SUBDEV_FORMAT_TRY) +
[PATCH v7 11/16] intel-ipu3: css: Compute and program ccs
A collection of routines that are mainly used to calculate the parameters for accelerator cluster. Signed-off-by: Yong Zhi --- drivers/media/pci/intel/ipu3/ipu3-css-params.c | 2907 drivers/media/pci/intel/ipu3/ipu3-css-params.h | 25 + 2 files changed, 2932 insertions(+) create mode 100644 drivers/media/pci/intel/ipu3/ipu3-css-params.c create mode 100644 drivers/media/pci/intel/ipu3/ipu3-css-params.h diff --git a/drivers/media/pci/intel/ipu3/ipu3-css-params.c b/drivers/media/pci/intel/ipu3/ipu3-css-params.c new file mode 100644 index 000..add2be4 --- /dev/null +++ b/drivers/media/pci/intel/ipu3/ipu3-css-params.c @@ -0,0 +1,2907 @@ +// SPDX-License-Identifier: GPL-2.0 +// Copyright (C) 2018 Intel Corporation + +#include + +#include "ipu3-css.h" +#include "ipu3-css-fw.h" +#include "ipu3-tables.h" + +#define DIV_ROUND_CLOSEST_DOWN(a, b) (((a) + ((b) / 2) - 1) / (b)) +#define roundclosest_down(a, b)(DIV_ROUND_CLOSEST_DOWN(a, b) * (b)) + +#define IPU3_UAPI_ANR_MAX_RESET((1 << 12) - 1) +#define IPU3_UAPI_ANR_MIN_RESET(((-1) << 12) + 1) + +struct ipu3_css_scaler_info { + unsigned int phase_step;/* Same for luma/chroma */ + int exp_shift; + + unsigned int phase_init;/* luma/chroma dependent */ + int pad_left; + int pad_right; + int crop_left; + int crop_top; +}; + +static unsigned int ipu3_css_scaler_get_exp(unsigned int counter, + unsigned int divider) +{ + int i = fls(divider) - fls(counter); + + if (i <= 0) + return 0; + + if (divider >> i < counter) + i = i - 1; + + return i; +} + +/* Set up the CSS scaler look up table */ +static void +ipu3_css_scaler_setup_lut(unsigned int taps, unsigned int input_width, + unsigned int output_width, int phase_step_correction, + const int *coeffs, unsigned int coeffs_size, + s8 coeff_lut[], struct ipu3_css_scaler_info *info) +{ + int tap, phase, phase_sum_left, phase_sum_right; + int exponent = ipu3_css_scaler_get_exp(output_width, input_width); + int mantissa = (1 << exponent) * output_width; + unsigned int phase_step; + + if (input_width == output_width) { + for (phase = 0; phase < IMGU_SCALER_PHASES; phase++) { + for (tap = 0; tap < taps; tap++) { + coeff_lut[phase * IMGU_SCALER_FILTER_TAPS + tap] + = 0; + } + } + + info->phase_step = IMGU_SCALER_PHASES * + (1 << IMGU_SCALER_PHASE_COUNTER_PREC_REF); + info->exp_shift = 0; + info->pad_left = 0; + info->pad_right = 0; + info->phase_init = 0; + info->crop_left = 0; + info->crop_top = 0; + return; + } + + for (phase = 0; phase < IMGU_SCALER_PHASES; phase++) { + for (tap = 0; tap < taps; tap++) { + /* flip table to for convolution reverse indexing */ + s64 coeff = coeffs[coeffs_size - + ((tap * (coeffs_size / taps)) + phase) - 1]; + coeff *= mantissa; + coeff = div64_long(coeff, input_width); + + /* Add +"0.5" */ + coeff += 1 << (IMGU_SCALER_COEFF_BITS - 1); + coeff >>= IMGU_SCALER_COEFF_BITS; + + coeff_lut[phase * IMGU_SCALER_FILTER_TAPS + tap] = + coeff; + } + } + + phase_step = IMGU_SCALER_PHASES * + (1 << IMGU_SCALER_PHASE_COUNTER_PREC_REF) * + output_width / input_width; + phase_step += phase_step_correction; + phase_sum_left = (taps / 2 * IMGU_SCALER_PHASES * + (1 << IMGU_SCALER_PHASE_COUNTER_PREC_REF)) - + (1 << (IMGU_SCALER_PHASE_COUNTER_PREC_REF - 1)); + phase_sum_right = (taps / 2 * IMGU_SCALER_PHASES * + (1 << IMGU_SCALER_PHASE_COUNTER_PREC_REF)) + + (1 << (IMGU_SCALER_PHASE_COUNTER_PREC_REF - 1)); + + info->exp_shift = IMGU_SCALER_MAX_EXPONENT_SHIFT - exponent; + info->pad_left = (phase_sum_left % phase_step == 0) ? + phase_sum_left / phase_step - 1 : phase_sum_left / phase_step; + info->pad_right = (phase_sum_right % phase_step == 0) ? + phase_sum_right / phase_step - 1 : phase_sum_right / phase_step; + info->phase_init = phase_sum_left - phase_step * info->pad_le
[PATCH v7 03/16] v4l: Add Intel IPU3 meta data uAPI
These meta formats are used on Intel IPU3 ImgU video queues to carry 3A statistics and ISP pipeline parameters. V4L2_META_FMT_IPU3_3A V4L2_META_FMT_IPU3_PARAMS Signed-off-by: Yong Zhi Signed-off-by: Chao C Li Signed-off-by: Rajmohan Mani --- Documentation/media/uapi/v4l/meta-formats.rst |1 + .../media/uapi/v4l/pixfmt-meta-intel-ipu3.rst | 181 ++ include/uapi/linux/intel-ipu3.h| 2819 3 files changed, 3001 insertions(+) create mode 100644 Documentation/media/uapi/v4l/pixfmt-meta-intel-ipu3.rst create mode 100644 include/uapi/linux/intel-ipu3.h diff --git a/Documentation/media/uapi/v4l/meta-formats.rst b/Documentation/media/uapi/v4l/meta-formats.rst index cf971d5..eafc534 100644 --- a/Documentation/media/uapi/v4l/meta-formats.rst +++ b/Documentation/media/uapi/v4l/meta-formats.rst @@ -12,6 +12,7 @@ These formats are used for the :ref:`metadata` interface only. .. toctree:: :maxdepth: 1 +pixfmt-meta-intel-ipu3 pixfmt-meta-d4xx pixfmt-meta-uvc pixfmt-meta-vsp1-hgo diff --git a/Documentation/media/uapi/v4l/pixfmt-meta-intel-ipu3.rst b/Documentation/media/uapi/v4l/pixfmt-meta-intel-ipu3.rst new file mode 100644 index 000..23b945b --- /dev/null +++ b/Documentation/media/uapi/v4l/pixfmt-meta-intel-ipu3.rst @@ -0,0 +1,181 @@ +.. -*- coding: utf-8; mode: rst -*- + +.. _intel-ipu3: + +** +V4L2_META_FMT_IPU3_PARAMS ('ip3p'), V4L2_META_FMT_IPU3_3A ('ip3s') +** + +.. c:type:: ipu3_uapi_stats_3a + +3A statistics += + +For IPU3 ImgU, the 3A statistics accelerators collect different statistics over +an input bayer frame. Those statistics, defined in data struct +:c:type:`ipu3_uapi_stats_3a`, are meta output obtained from "ipu3-imgu 3a stat" +video node, which are then passed to user space for statistics analysis +using :c:type:`v4l2_meta_format` interface. + +The statistics collected are AWB (Auto-white balance) RGBS (Red, Green, Blue and +Saturation measure) cells, AWB filter response, AF (Auto-focus) filter response, +and AE (Auto-exposure) histogram. + +struct :c:type:`ipu3_uapi_4a_config` saves configurable parameters for all above. + + +.. code-block:: c + + + struct ipu3_uapi_stats_3a { + struct ipu3_uapi_awb_raw_buffer awb_raw_buffer +__attribute__((aligned(32))); + struct ipu3_uapi_ae_raw_buffer_aligned + ae_raw_buffer[IPU3_UAPI_MAX_STRIPES]; + struct ipu3_uapi_af_raw_buffer af_raw_buffer; + struct ipu3_uapi_awb_fr_raw_buffer awb_fr_raw_buffer; + struct ipu3_uapi_4a_config stats_4a_config; + __u32 ae_join_buffers; + __u8 padding[28]; + struct ipu3_uapi_stats_3a_bubble_info_per_stripe + stats_3a_bubble_per_stripe; + struct ipu3_uapi_ff_status stats_3a_status; + } __packed; + + +.. c:type:: ipu3_uapi_params + +Pipeline parameters +=== + +IPU3 pipeline has a number of image processing stages, each of which takes a +set of parameters as input. The major stages of pipelines are shown here: + +Raw pixels -> Bayer Downscaling -> Optical Black Correction -> + +Linearization -> Lens Shading Correction -> White Balance / Exposure / + +Focus Apply -> Bayer Noise Reduction -> ANR -> Demosaicing -> Color + +Correction Matrix -> Gamma correction -> Color Space Conversion -> + +Chroma Down Scaling -> Chromatic Noise Reduction -> Total Color + +Correction -> XNR3 -> TNR -> DDR + +The table below presents a description of the above algorithms. + + === +NameDescription + === +Optical Black Correction Optical Black Correction block subtracts a pre-defined +value from the respective pixel values to obtain better +image quality. +Defined in :c:type:`ipu3_uapi_obgrid_param`. +Linearization This algo block uses linearization parameters to +address non-linearity sensor effects. The Lookup table +table is defined in +:c:type:`ipu3_uapi_isp_lin_vmem_params`. +SHD Lens shading correction is used to correct spatial +non-uniformity of the pixel response due to optical +lens shading. This is done by applying a different gain +for each pixel. The gain, black level etc are +configured in :c:type:`ipu3_uapi_shd_config_static`. +BNR Bayer noise reduction block removes image noise by +applying a bilateral filte
[PATCH v7 12/16] intel-ipu3: css: Initialize css hardware
This patch implements the functions to initialize and configure IPU3 h/w such as clock, irq and power. Signed-off-by: Yong Zhi Signed-off-by: Tomasz Figa --- drivers/media/pci/intel/ipu3/ipu3-css.c | 537 drivers/media/pci/intel/ipu3/ipu3-css.h | 203 2 files changed, 740 insertions(+) create mode 100644 drivers/media/pci/intel/ipu3/ipu3-css.c create mode 100644 drivers/media/pci/intel/ipu3/ipu3-css.h diff --git a/drivers/media/pci/intel/ipu3/ipu3-css.c b/drivers/media/pci/intel/ipu3/ipu3-css.c new file mode 100644 index 000..164830f --- /dev/null +++ b/drivers/media/pci/intel/ipu3/ipu3-css.c @@ -0,0 +1,537 @@ +// SPDX-License-Identifier: GPL-2.0 +// Copyright (C) 2018 Intel Corporation + +#include +#include + +#include "ipu3-css.h" +#include "ipu3-css-fw.h" +#include "ipu3-css-params.h" +#include "ipu3-dmamap.h" +#include "ipu3-tables.h" + +/* IRQ configuration */ +#define IMGU_IRQCTRL_IRQ_MASK (IMGU_IRQCTRL_IRQ_SP1 | \ +IMGU_IRQCTRL_IRQ_SP2 | \ +IMGU_IRQCTRL_IRQ_SW_PIN(0) | \ +IMGU_IRQCTRL_IRQ_SW_PIN(1)) + +/*** css hw ***/ + +/* In the style of writesl() defined in include/asm-generic/io.h */ +static inline void writes(const void *mem, ssize_t count, void __iomem *addr) +{ + if (count >= 4) { + const u32 *buf = mem; + + count /= 4; + do { + writel(*buf++, addr); + addr += 4; + } while (--count); + } +} + +/* Wait until register `reg', masked with `mask', becomes `cmp' */ +static int ipu3_hw_wait(void __iomem *base, int reg, u32 mask, u32 cmp) +{ + u32 val; + + return readl_poll_timeout(base + reg, val, (val & mask) == cmp, + 1000, 100 * 1000); +} + +/* Initialize the IPU3 CSS hardware and associated h/w blocks */ + +int ipu3_css_set_powerup(struct device *dev, void __iomem *base) +{ + static const unsigned int freq = 450; + u32 pm_ctrl, state, val; + + dev_dbg(dev, "%s\n", __func__); + /* Clear the CSS busy signal */ + readl(base + IMGU_REG_GP_BUSY); + writel(0, base + IMGU_REG_GP_BUSY); + + /* Wait for idle signal */ + if (ipu3_hw_wait(base, IMGU_REG_STATE, IMGU_STATE_IDLE_STS, +IMGU_STATE_IDLE_STS)) { + dev_err(dev, "failed to set CSS idle\n"); + goto fail; + } + + /* Reset the css */ + writel(readl(base + IMGU_REG_PM_CTRL) | IMGU_PM_CTRL_FORCE_RESET, + base + IMGU_REG_PM_CTRL); + + usleep_range(200, 300); + + /** Prepare CSS */ + + pm_ctrl = readl(base + IMGU_REG_PM_CTRL); + state = readl(base + IMGU_REG_STATE); + + dev_dbg(dev, "CSS pm_ctrl 0x%x state 0x%x (power %s)\n", + pm_ctrl, state, state & IMGU_STATE_POWER_DOWN ? "down" : "up"); + + /* Power up CSS using wrapper */ + if (state & IMGU_STATE_POWER_DOWN) { + writel(IMGU_PM_CTRL_RACE_TO_HALT | IMGU_PM_CTRL_START, + base + IMGU_REG_PM_CTRL); + if (ipu3_hw_wait(base, IMGU_REG_PM_CTRL, +IMGU_PM_CTRL_START, 0)) { + dev_err(dev, "failed to power up CSS\n"); + goto fail; + } + usleep_range(2000, 3000); + } else { + writel(IMGU_PM_CTRL_RACE_TO_HALT, base + IMGU_REG_PM_CTRL); + } + + /* Set the busy bit */ + writel(readl(base + IMGU_REG_GP_BUSY) | 1, base + IMGU_REG_GP_BUSY); + + /* Set CSS clock frequency */ + pm_ctrl = readl(base + IMGU_REG_PM_CTRL); + val = pm_ctrl & ~(IMGU_PM_CTRL_CSS_PWRDN | IMGU_PM_CTRL_RST_AT_EOF); + writel(val, base + IMGU_REG_PM_CTRL); + writel(0, base + IMGU_REG_GP_BUSY); + if (ipu3_hw_wait(base, IMGU_REG_STATE, +IMGU_STATE_PWRDNM_FSM_MASK, 0)) { + dev_err(dev, "failed to pwrdn CSS\n"); + goto fail; + } + val = (freq / IMGU_SYSTEM_REQ_FREQ_DIVIDER) & IMGU_SYSTEM_REQ_FREQ_MASK; + writel(val, base + IMGU_REG_SYSTEM_REQ); + writel(1, base + IMGU_REG_GP_BUSY); + writel(readl(base + IMGU_REG_PM_CTRL) | IMGU_PM_CTRL_FORCE_HALT, + base + IMGU_REG_PM_CTRL); + if (ipu3_hw_wait(base, IMGU_REG_STATE, IMGU_STATE_HALT_STS, +IMGU_STATE_HALT_STS)) { + dev_err(dev, "failed to halt CSS\n"); + goto fail; + } + + writel(readl(base + IMGU_REG_PM_CTRL) | IMGU_PM_CTRL_START, + base + IMGU_REG_PM_CTRL); + if (ipu3_hw_wait(base, IMGU_REG_PM_
[PATCH v7 06/16] intel-ipu3: mmu: Implement driver
From: Tomasz Figa This driver translates IO virtual address to physical address based on two levels page tables. Signed-off-by: Tomasz Figa Signed-off-by: Yong Zhi --- drivers/media/pci/intel/ipu3/ipu3-mmu.c | 560 drivers/media/pci/intel/ipu3/ipu3-mmu.h | 35 ++ 2 files changed, 595 insertions(+) create mode 100644 drivers/media/pci/intel/ipu3/ipu3-mmu.c create mode 100644 drivers/media/pci/intel/ipu3/ipu3-mmu.h diff --git a/drivers/media/pci/intel/ipu3/ipu3-mmu.c b/drivers/media/pci/intel/ipu3/ipu3-mmu.c new file mode 100644 index 000..b66734a --- /dev/null +++ b/drivers/media/pci/intel/ipu3/ipu3-mmu.c @@ -0,0 +1,560 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (C) 2018 Intel Corporation. + * Copyright 2018 Google LLC. + * + * Author: Tuukka Toivonen + * Author: Sakari Ailus + * Author: Samu Onkalo + * Author: Tomasz Figa + * + */ + +#include +#include +#include +#include +#include + +#include + +#include "ipu3-mmu.h" + +#define IPU3_PAGE_SHIFT12 +#define IPU3_PAGE_SIZE (1UL << IPU3_PAGE_SHIFT) + +#define IPU3_PT_BITS 10 +#define IPU3_PT_PTES (1UL << IPU3_PT_BITS) +#define IPU3_PT_SIZE (IPU3_PT_PTES << 2) +#define IPU3_PT_ORDER (IPU3_PT_SIZE >> PAGE_SHIFT) + +#define IPU3_ADDR2PTE(addr)((addr) >> IPU3_PAGE_SHIFT) +#define IPU3_PTE2ADDR(pte) ((phys_addr_t)(pte) << IPU3_PAGE_SHIFT) + +#define IPU3_L2PT_SHIFTIPU3_PT_BITS +#define IPU3_L2PT_MASK ((1UL << IPU3_L2PT_SHIFT) - 1) + +#define IPU3_L1PT_SHIFTIPU3_PT_BITS +#define IPU3_L1PT_MASK ((1UL << IPU3_L1PT_SHIFT) - 1) + +#define IPU3_MMU_ADDRESS_BITS (IPU3_PAGE_SHIFT + \ +IPU3_L2PT_SHIFT + \ +IPU3_L1PT_SHIFT) + +#define IMGU_REG_BASE 0x4000 +#define REG_TLB_INVALIDATE (IMGU_REG_BASE + 0x300) +#define TLB_INVALIDATE 1 +#define REG_L1_PHYS(IMGU_REG_BASE + 0x304) /* 27-bit pfn */ +#define REG_GP_HALT(IMGU_REG_BASE + 0x5dc) +#define REG_GP_HALTED (IMGU_REG_BASE + 0x5e0) + +struct ipu3_mmu { + struct device *dev; + void __iomem *base; + /* protect access to l2pts, l1pt */ + spinlock_t lock; + + void *dummy_page; + u32 dummy_page_pteval; + + u32 *dummy_l2pt; + u32 dummy_l2pt_pteval; + + u32 **l2pts; + u32 *l1pt; + + struct ipu3_mmu_info geometry; +}; + +static inline struct ipu3_mmu *to_ipu3_mmu(struct ipu3_mmu_info *info) +{ + return container_of(info, struct ipu3_mmu, geometry); +} + +/** + * ipu3_mmu_tlb_invalidate - invalidate translation look-aside buffer + * @mmu: MMU to perform the invalidate operation on + * + * This function invalidates the whole TLB. Must be called when the hardware + * is powered on. + */ +static void ipu3_mmu_tlb_invalidate(struct ipu3_mmu *mmu) +{ + writel(TLB_INVALIDATE, mmu->base + REG_TLB_INVALIDATE); +} + +static void call_if_ipu3_is_powered(struct ipu3_mmu *mmu, + void (*func)(struct ipu3_mmu *mmu)) +{ + pm_runtime_get_noresume(mmu->dev); + if (pm_runtime_active(mmu->dev)) + func(mmu); + pm_runtime_put(mmu->dev); +} + +/** + * ipu3_mmu_set_halt - set CIO gate halt bit + * @mmu: MMU to set the CIO gate bit in. + * @halt: Desired state of the gate bit. + * + * This function sets the CIO gate bit that controls whether external memory + * accesses are allowed. Must be called when the hardware is powered on. + */ +static void ipu3_mmu_set_halt(struct ipu3_mmu *mmu, bool halt) +{ + int ret; + u32 val; + + writel(halt, mmu->base + REG_GP_HALT); + ret = readl_poll_timeout(mmu->base + REG_GP_HALTED, +val, (val & 1) == halt, 1000, 10); + + if (ret) + dev_err(mmu->dev, "failed to %s CIO gate halt\n", + halt ? "set" : "clear"); +} + +/** + * ipu3_mmu_alloc_page_table - allocate a pre-filled page table + * @pteval: Value to initialize for page table entries with. + * + * Return: Pointer to allocated page table or NULL on failure. + */ +static u32 *ipu3_mmu_alloc_page_table(u32 pteval) +{ + u32 *pt; + int pte; + + pt = (u32 *)__get_free_page(GFP_KERNEL); + if (!pt) + return NULL; + + for (pte = 0; pte < IPU3_PT_PTES; pte++) + pt[pte] = pteval; + + set_memory_uc((unsigned long int)pt, IPU3_PT_ORDER); + + return pt; +} + +/** + * ipu3_mmu_free_page_table - free page table + * @pt: Page table to free. + */ +static void ipu3_mmu_free_page_table(u32 *pt) +{ + set_memory_wb((unsigned long int)pt, IPU3_PT_ORDER); + free_page((unsigned long)pt); +} + +/** + * address_to_pte_idx - split IOVA into L1 and L2 page
[PATCH v7 02/16] doc-rst: Add Intel IPU3 documentation
From: Rajmohan Mani This patch adds the details about the IPU3 Imaging Unit driver. Change-Id: I560cecf673df2dcc3ec72767cf8077708d649656 Signed-off-by: Rajmohan Mani --- Documentation/media/v4l-drivers/index.rst | 1 + Documentation/media/v4l-drivers/ipu3.rst | 326 ++ 2 files changed, 327 insertions(+) create mode 100644 Documentation/media/v4l-drivers/ipu3.rst diff --git a/Documentation/media/v4l-drivers/index.rst b/Documentation/media/v4l-drivers/index.rst index 679238e..179a393 100644 --- a/Documentation/media/v4l-drivers/index.rst +++ b/Documentation/media/v4l-drivers/index.rst @@ -44,6 +44,7 @@ For more details see the file COPYING in the source distribution of Linux. davinci-vpbe fimc imx + ipu3 ivtv max2175 meye diff --git a/Documentation/media/v4l-drivers/ipu3.rst b/Documentation/media/v4l-drivers/ipu3.rst new file mode 100644 index 000..045bf42 --- /dev/null +++ b/Documentation/media/v4l-drivers/ipu3.rst @@ -0,0 +1,326 @@ +.. include:: + +=== +Intel Image Processing Unit 3 (IPU3) Imaging Unit (ImgU) driver +=== + +Copyright |copy| 2018 Intel Corporation + +Introduction + + +This file documents Intel IPU3 (3rd generation Image Processing Unit) Imaging +Unit driver located under drivers/media/pci/intel/ipu3. + +The Intel IPU3 found in certain Kaby Lake (as well as certain Sky Lake) +platforms (U/Y processor lines) is made up of two parts namely Imaging Unit +(ImgU) and CIO2 device (MIPI CSI2 receiver). + +The CIO2 device receives the raw bayer data from the sensors and outputs the +frames in a format that is specific to IPU3 (for consumption by IPU3 ImgU). +CIO2 driver is available as drivers/media/pci/intel/ipu3/ipu3-cio2* and is +enabled through the CONFIG_VIDEO_IPU3_CIO2 config option. + +The Imaging Unit (ImgU) is responsible for processing images captured +through IPU3 CIO2 device. The ImgU driver sources can be found under +drivers/media/pci/intel/ipu3 directory. The driver is enabled through the +CONFIG_VIDEO_IPU3_IMGU config option. + +The two driver modules are named ipu3-csi2 and ipu3-imgu, respectively. + +The driver has been tested on Kaby Lake platforms (U/Y processor lines). + +The driver implements V4L2, Media controller and V4L2 sub-device interfaces. +Camera sensors that have CSI-2 bus, which are connected to the IPU3 CIO2 +device are supported. Support for lens and flash drivers depends on the +above sensors. + +ImgU device nodes += + +The ImgU is represented as two V4L2 subdevs, each of which provides a V4L2 +subdev interface to the user space. + +Each V4L2 subdev represents a pipe, which can support a maximum of 2 +streams. A private ioctl can be used to configure the mode (video or still) +of the pipe. + +This helps to support advanced camera features like Continuous View Finder +(CVF) and Snapshot During Video(SDV). + +CIO2 device +=== + +The CIO2 is represented as a single V4L2 subdev, which provides a V4L2 subdev +interface to the user space. There is a video node for each CSI-2 receiver, +with a single media controller interface for the entire device. + +Media controller + + +The media device interface allows to configure the ImgU links, which defines +the behavior of the IPU3 firmware. + +Device operation + + +With IPU3, once the input video node ("ipu3-imgu 0/1":0, +in : format) is queued with buffer (in packed raw bayer +format), IPU3 ISP starts processing the buffer and produces the video output +in YUV format and statistics output on respective output nodes. The driver +is expected to have buffers ready for all of parameter, output and +statistics nodes, when input video node is queued with buffer. + +At a minimum, all of input, main output, 3A statistics and viewfinder +video nodes should be enabled for IPU3 to start image processing. + +Each ImgU V4L2 subdev has the following set of video nodes. + +input, output and viewfinder video nodes + + +The frames (in packed raw bayer format specific to IPU3) received by the +input video node is processed by the IPU3 Imaging Unit and is output to 2 +video nodes, with each targeting different purpose (main output and viewfinder +output). + +Details on raw bayer format specific to IPU3 can be found as below. +Documentation/media/uapi/v4l/pixfmt-meta-intel-ipu3.rst + +The driver supports V4L2 Video Capture Interface as defined at :ref:`devices`. + +Only the multi-planar API is supported. More details can be found at +:ref:`planar-apis`. + + +parameters video node +- + +The parameter video node receives the ISP algorithm parameters that are used +to configure how the ISP algorithms process the image. + +Details on raw bayer format specific to IPU3 can be found as below. +Documentation/medi
[PATCH v7 07/16] intel-ipu3: Implement DMA mapping functions
From: Tomasz Figa This driver uses IOVA space for buffer mapping through IPU3 MMU to transfer data between imaging pipelines and system DDR. Signed-off-by: Tomasz Figa Signed-off-by: Yong Zhi --- drivers/media/pci/intel/ipu3/ipu3-dmamap.c | 270 + drivers/media/pci/intel/ipu3/ipu3-dmamap.h | 22 +++ 2 files changed, 292 insertions(+) create mode 100644 drivers/media/pci/intel/ipu3/ipu3-dmamap.c create mode 100644 drivers/media/pci/intel/ipu3/ipu3-dmamap.h diff --git a/drivers/media/pci/intel/ipu3/ipu3-dmamap.c b/drivers/media/pci/intel/ipu3/ipu3-dmamap.c new file mode 100644 index 000..93a393d --- /dev/null +++ b/drivers/media/pci/intel/ipu3/ipu3-dmamap.c @@ -0,0 +1,270 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (C) 2018 Intel Corporation + * Copyright 2018 Google LLC. + * + * Author: Tomasz Figa + * Author: Yong Zhi + */ + +#include + +#include "ipu3.h" +#include "ipu3-css-pool.h" +#include "ipu3-mmu.h" + +/* + * Free a buffer allocated by ipu3_dmamap_alloc_buffer() + */ +static void ipu3_dmamap_free_buffer(struct page **pages, + size_t size) +{ + int count = size >> PAGE_SHIFT; + + while (count--) + __free_page(pages[count]); + kvfree(pages); +} + +/* + * Based on the implementation of __iommu_dma_alloc_pages() + * defined in drivers/iommu/dma-iommu.c + */ +static struct page **ipu3_dmamap_alloc_buffer(size_t size, + unsigned long order_mask, + gfp_t gfp) +{ + struct page **pages; + unsigned int i = 0, count = size >> PAGE_SHIFT; + const gfp_t high_order_gfp = __GFP_NOWARN | __GFP_NORETRY; + + /* Allocate mem for array of page ptrs */ + pages = kvmalloc_array(count, sizeof(*pages), GFP_KERNEL); + + if (!pages) + return NULL; + + order_mask &= (2U << MAX_ORDER) - 1; + if (!order_mask) + return NULL; + + gfp |= __GFP_HIGHMEM | __GFP_ZERO; + + while (count) { + struct page *page = NULL; + unsigned int order_size; + + for (order_mask &= (2U << __fls(count)) - 1; +order_mask; order_mask &= ~order_size) { + unsigned int order = __fls(order_mask); + + order_size = 1U << order; + page = alloc_pages((order_mask - order_size) ? + gfp | high_order_gfp : gfp, order); + if (!page) + continue; + if (!order) + break; + if (!PageCompound(page)) { + split_page(page, order); + break; + } + + __free_pages(page, order); + } + if (!page) { + ipu3_dmamap_free_buffer(pages, i << PAGE_SHIFT); + return NULL; + } + count -= order_size; + while (order_size--) + pages[i++] = page++; + } + + return pages; +} + +/** + * ipu3_dmamap_alloc - allocate and map a buffer into KVA + * @imgu: struct device pointer + * @map: struct to store mapping variables + * @len: size required + * + * Returns: + * KVA on success + * %NULL on failure + */ +void *ipu3_dmamap_alloc(struct imgu_device *imgu, struct ipu3_css_map *map, + size_t len) +{ + unsigned long shift = iova_shift(&imgu->iova_domain); + unsigned int alloc_sizes = imgu->mmu->pgsize_bitmap; + struct device *dev = &imgu->pci_dev->dev; + size_t size = PAGE_ALIGN(len); + struct page **pages; + dma_addr_t iovaddr; + struct iova *iova; + int i, rval; + + dev_dbg(dev, "%s: allocating %zu\n", __func__, size); + + iova = alloc_iova(&imgu->iova_domain, size >> shift, + imgu->mmu->aperture_end >> shift, 0); + if (!iova) + return NULL; + + pages = ipu3_dmamap_alloc_buffer(size, alloc_sizes >> PAGE_SHIFT, +GFP_KERNEL); + if (!pages) + goto out_free_iova; + + /* Call IOMMU driver to setup pgt */ + iovaddr = iova_dma_addr(&imgu->iova_domain, iova); + for (i = 0; i < size / PAGE_SIZE; ++i) { + rval = ipu3_mmu_map(imgu->mmu, iovaddr, + page_to_phys(pages[i]), PAGE_SIZE); + if (rval) + goto out_unmap; + + iovaddr += PAGE_SIZE; + } + + /* Now grab a virtual region */ + map->vma = __get_vm_area(
[PATCH v7 04/16] intel-ipu3: abi: Add register definitions and enum
Add macros and enums used for IPU3 firmware interface. Signed-off-by: Yong Zhi Signed-off-by: Rajmohan Mani --- drivers/media/pci/intel/ipu3/ipu3-abi.h | 661 1 file changed, 661 insertions(+) create mode 100644 drivers/media/pci/intel/ipu3/ipu3-abi.h diff --git a/drivers/media/pci/intel/ipu3/ipu3-abi.h b/drivers/media/pci/intel/ipu3/ipu3-abi.h new file mode 100644 index 000..ac08ad3 --- /dev/null +++ b/drivers/media/pci/intel/ipu3/ipu3-abi.h @@ -0,0 +1,661 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* Copyright (C) 2018 Intel Corporation */ + +#ifndef __IPU3_ABI_H +#define __IPU3_ABI_H + +#include + +/*** IMGU Hardware information ***/ + +typedef u32 imgu_addr_t; + +#define IMGU_ISP_VMEM_ALIGN128 +#define IMGU_DVS_BLOCK_W 64 +#define IMGU_DVS_BLOCK_H 32 +#define IMGU_GDC_BUF_X (2 * IMGU_DVS_BLOCK_W) +#define IMGU_GDC_BUF_Y IMGU_DVS_BLOCK_H +/* n = 0..1 */ +#define IMGU_SP_PMEM_BASE(n) (0x2 + (n) * 0x4000) +#define IMGU_MAX_BQ_GRID_WIDTH 80 +#define IMGU_MAX_BQ_GRID_HEIGHT60 +#define IMGU_OBGRID_TILE_SIZE 16 +#define IMGU_PIXELS_PER_WORD 50 +#define IMGU_BYTES_PER_WORD64 +#define IMGU_STRIPE_FIXED_HALF_OVERLAP 2 +#define IMGU_SHD_SETS 3 +#define IMGU_BDS_MIN_CLIP_VAL 0 +#define IMGU_BDS_MAX_CLIP_VAL 2 + +#define IMGU_ABI_AWB_MAX_CELLS_PER_SET 160 +#define IMGU_ABI_AF_MAX_CELLS_PER_SET 32 +#define IMGU_ABI_AWB_FR_MAX_CELLS_PER_SET 32 + +#define IMGU_ABI_ACC_OP_IDLE 0 +#define IMGU_ABI_ACC_OP_END_OF_ACK 1 +#define IMGU_ABI_ACC_OP_END_OF_OPS 2 +#define IMGU_ABI_ACC_OP_NO_OPS 3 + +#define IMGU_ABI_ACC_OPTYPE_PROCESS_LINES 0 +#define IMGU_ABI_ACC_OPTYPE_TRANSFER_DATA 1 + +/* Register definitions */ + +/* PM_CTRL_0_5_0_IMGHMMADR */ +#define IMGU_REG_PM_CTRL 0x0 +#define IMGU_PM_CTRL_START BIT(0) +#define IMGU_PM_CTRL_CFG_DONE BIT(1) +#define IMGU_PM_CTRL_RACE_TO_HALT BIT(2) +#define IMGU_PM_CTRL_NACK_ALL BIT(3) +#define IMGU_PM_CTRL_CSS_PWRDN BIT(4) +#define IMGU_PM_CTRL_RST_AT_EOFBIT(5) +#define IMGU_PM_CTRL_FORCE_HALTBIT(6) +#define IMGU_PM_CTRL_FORCE_UNHALT BIT(7) +#define IMGU_PM_CTRL_FORCE_PWRDN BIT(8) +#define IMGU_PM_CTRL_FORCE_RESET BIT(9) + +/* SYSTEM_REQ_0_5_0_IMGHMMADR */ +#define IMGU_REG_SYSTEM_REQ0x18 +#define IMGU_SYSTEM_REQ_FREQ_MASK 0x3f +#define IMGU_SYSTEM_REQ_FREQ_DIVIDER 25 +#define IMGU_REG_INT_STATUS0x30 +#define IMGU_REG_INT_ENABLE0x34 +#define IMGU_REG_INT_CSS_IRQ BIT(31) +/* STATE_0_5_0_IMGHMMADR */ +#define IMGU_REG_STATE 0x130 +#define IMGU_STATE_HALT_STSBIT(0) +#define IMGU_STATE_IDLE_STSBIT(1) +#define IMGU_STATE_POWER_UPBIT(2) +#define IMGU_STATE_POWER_DOWN BIT(3) +#define IMGU_STATE_CSS_BUSY_MASK 0xc0 +#define IMGU_STATE_PM_FSM_MASK 0x180 +#define IMGU_STATE_PWRDNM_FSM_MASK 0x1E0 +/* PM_STS_0_5_0_IMGHMMADR */ +#define IMGU_REG_PM_STS0x140 + +#define IMGU_REG_BASE 0x4000 + +#define IMGU_REG_ISP_CTRL (IMGU_REG_BASE + 0x00) +#define IMGU_CTRL_RST BIT(0) +#define IMGU_CTRL_STARTBIT(1) +#define IMGU_CTRL_BREAKBIT(2) +#define IMGU_CTRL_RUN BIT(3) +#define IMGU_CTRL_BROKEN BIT(4) +#define IMGU_CTRL_IDLE BIT(5) +#define IMGU_CTRL_SLEEPING BIT(6) +#define IMGU_CTRL_STALLING BIT(7) +#define IMGU_CTRL_IRQ_CLEARBIT(8) +#define IMGU_CTRL_IRQ_READYBIT(10) +#define IMGU_CTRL_IRQ_SLEEPING BIT(11) +#define IMGU_CTRL_ICACHE_INV BIT(12) +#define IMGU_CTRL_IPREFETCH_EN BIT(13) +#define IMGU_REG_ISP_START_ADDR(IMGU_REG_BASE + 0x04) +#define IMGU_REG_ISP_ICACHE_ADDR (IMGU_REG_BASE + 0x10) +#define IMGU_REG_ISP_PC(IMGU_REG_BASE + 0x1c) + +/* SP Registers, sp = 0:SP0; 1:SP1 */ +#define IMGU_REG_SP_CTRL(sp) (IMGU_REG_BASE + (sp) * 0x100 + 0x100) + /* For bits in IMGU_REG_SP_CTRL, see IMGU_CTRL_* */ +#define IMGU_REG_SP_START_ADDR(sp) (IMGU_REG_BASE + (sp) * 0x100
[PATCH v7 00/16] Intel IPU3 ImgU patchset
Hi, This series adds support for the Intel IPU3 (Image Processing Unit) ImgU which is essentially a modern memory-to-memory ISP. It implements raw Bayer to YUV image format conversion as well as a large number of other pixel processing algorithms for improving the image quality. Meta data formats are defined for image statistics (3A, i.e. automatic white balance, exposure and focus, histogram and local area contrast enhancement) as well as for the pixel processing algorithm parameters. The documentation for these formats is currently not included in the patchset but will be added in a future version of this set. The algorithm parameters need to be considered specific to a given frame and typically a large number of these parameters change on frame to frame basis. Additionally, the parameters are highly structured (and not a flat space of independent configuration primitives). They also reflect the data structures used by the firmware and the hardware. On top of that, the algorithms require highly specialized user space to make meaningful use of them. For these reasons it has been chosen video buffers to pass the parameters to the device. On individual patches: The heart of ImgU is the CSS, or Camera Subsystem, which contains the image processors and HW accelerators. The 3A statistics and other firmware parameter computation related functions are implemented in patch 11. All IPU3 pipeline default settings can be found in patch 10. To access DDR via ImgU's own memory space, IPU3 is also equipped with its own MMU unit, the driver is implemented in patch 6. Patch 7 uses above driver for DMA mapping operation. The communication between IPU3 firmware and driver is implemented with circular queues in patch 8. Patch 9 provide some utility functions and manage IPU3 fw download and install. The firmware which is called ipu3-fw.bin can be downloaded from: git://git.kernel.org/pub/scm/linux/kernel/git/firmware/linux-firmware.git (commit 2c27b0cb02f18c022d8378e0e1abaf8b7ae8188f) Firmware ABI is defined in patches 4 and 5. Patches 12 and 13 are of the same file, the former contains all h/w programming related code, the latter implements interface functions for access fw & hw capabilities. Patch 14 has a dependency on Sakari's V4L2_BUF_TYPE_META_OUTPUT work: https://patchwork.kernel.org/patch/9976295/> Patch 15 represents the top level that glues all of the other components together, passing arguments between the components. Patch 16 is a recent effort to extend v6 for advanced camera features like Continuous View Finder (CVF) and Snapshot During Video(SDV) support. Link to user space implementation: git clone https://chromium.googlesource.com/chromiumos/platform/arc-camera ImgU media topology print: # media-ctl -d /dev/media0 -p Media controller API version 4.19.0 Media device information driver ipu3-imgu model ipu3-imgu serial bus infoPCI::00:05.0 hw revision 0x80862015 driver version 4.19.0 Device topology - entity 1: ipu3-imgu 0 (5 pads, 5 links) type V4L2 subdev subtype Unknown flags 0 device node name /dev/v4l-subdev0 pad0: Sink [fmt:UYVY8_2X8/1920x1080 field:none colorspace:unknown crop:(0,0)/1920x1080 compose:(0,0)/1920x1080] <- "ipu3-imgu 0 input":0 [] pad1: Sink [fmt:UYVY8_2X8/1920x1080 field:none colorspace:unknown] <- "ipu3-imgu 0 parameters":0 [] pad2: Source [fmt:UYVY8_2X8/1920x1080 field:none colorspace:unknown] -> "ipu3-imgu 0 output":0 [] pad3: Source [fmt:UYVY8_2X8/1920x1080 field:none colorspace:unknown] -> "ipu3-imgu 0 viewfinder":0 [] pad4: Source [fmt:UYVY8_2X8/1920x1080 field:none colorspace:unknown] -> "ipu3-imgu 0 3a stat":0 [] - entity 7: ipu3-imgu 1 (5 pads, 5 links) type V4L2 subdev subtype Unknown flags 0 device node name /dev/v4l-subdev1 pad0: Sink [fmt:UYVY8_2X8/1920x1080 field:none colorspace:unknown crop:(0,0)/1920x1080 compose:(0,0)/1920x1080] <- "ipu3-imgu 1 input":0 [] pad1: Sink [fmt:UYVY8_2X8/1920x1080 field:none colorspace:unknown] <- "ipu3-imgu 1 parameters":0 [] pad2: Source [fmt:UYVY8_2X8/1920x1080 field:none colorspace:unknown] -> "ipu3-imgu 1 output":0 [] pad3: Source [fmt:UYVY8_2X8/1920x1080 field:none colorspace:unknown] -> "ipu3-imgu 1 viewfinder":0 [] pad4: Source [fmt:UYVY8_2X8/1920x1080 field:none colorspace:unknown] -> "ipu3-imgu 1 3a stat":0 [] - entity 17: ipu3-imgu 0 input (1 pad, 1 link) type Node subtype V4L flags 0 device node name /dev
RE: [PATCH v6 12/12] intel-ipu3: Add imgu top level pci device driver
Hi, Tomasz, > -Original Message- > From: linux-media-ow...@vger.kernel.org [mailto:linux-media- > ow...@vger.kernel.org] On Behalf Of Tomasz Figa > Sent: Tuesday, September 18, 2018 10:23 AM > To: Zhi, Yong > Cc: Linux Media Mailing List ; Sakari Ailus > ; Mani, Rajmohan > ; Toivonen, Tuukka > ; Hu, Jerry W ; Zheng, > Jian Xu > Subject: Re: [PATCH v6 12/12] intel-ipu3: Add imgu top level pci device > driver > > On Mon, Sep 17, 2018 at 5:20 AM Zhi, Yong wrote: > > > > Hi, Tomasz, > > > > Thanks for the code review. > > > > > -Original Message- > > > From: linux-media-ow...@vger.kernel.org [mailto:linux-media- > > > ow...@vger.kernel.org] On Behalf Of Tomasz Figa > > > Sent: Monday, July 2, 2018 3:08 AM > > > To: Zhi, Yong > > > Cc: Linux Media Mailing List ; Sakari > > > Ailus ; Mani, Rajmohan > > > ; Toivonen, Tuukka > > > ; Hu, Jerry W ; > > > Zheng, Jian Xu > > > Subject: Re: [PATCH v6 12/12] intel-ipu3: Add imgu top level pci > > > device driver > > > > > > Hi Yong, > > > > > > On Fri, Mar 30, 2018 at 11:15 AM Yong Zhi > wrote: > > > > +/* > > > > + * Queue as many buffers to CSS as possible. If all buffers don't > > > > +fit into > > > > + * CSS buffer queues, they remain unqueued and will be queued later. > > > > + */ > > > > +int imgu_queue_buffers(struct imgu_device *imgu, bool initial) { > > > > + unsigned int node; > > > > + int r = 0; > > > > + struct imgu_buffer *ibuf; > > > > + > > > > + if (!ipu3_css_is_streaming(&imgu->css)) > > > > + return 0; > > > > + > > > > + mutex_lock(&imgu->lock); > > > > + > > > > + /* Buffer set is queued to FW only when input buffer is ready */ > > > > + if (!imgu_queue_getbuf(imgu, IMGU_NODE_IN)) { > > > > + mutex_unlock(&imgu->lock); > > > > + return 0; > > > > + } > > > > + for (node = IMGU_NODE_IN + 1; 1; node = (node + 1) % > > > > + IMGU_NODE_NUM) { > > > > > > Shouldn't we make (node != IMGU_NODE_IN || > imgu_queue_getbuf(imgu, > > > IMGU_NODE_IN)) the condition here, rather than 1? > > > > > > This would also let us remove the explicit call to > > > imgu_queue_getbuf() above the loop. > > > > > > > Ack, will make the suggested changes regarding the loop condition > evaluation. > > Just to make sure, the suggestion also includes starting from > IMGU_NODE_IN (not + 1), i.e. > > for (node = IMGU_NODE_IN; > node != IMGU_NODE_IN || imgu_queue_getbuf(imgu, IMGU_NODE_IN); > node = (node + 1) % IMGU_NODE_NUM) { > // ... > } > Thanks for the clarification. > > > > +static int __maybe_unused imgu_suspend(struct device *dev) { > > > > + struct pci_dev *pci_dev = to_pci_dev(dev); > > > > + struct imgu_device *imgu = pci_get_drvdata(pci_dev); > > > > + unsigned long expire; > > > > + > > > > + dev_dbg(dev, "enter %s\n", __func__); > > > > + imgu->suspend_in_stream = ipu3_css_is_streaming(&imgu- > >css); > > > > + if (!imgu->suspend_in_stream) > > > > + goto out; > > > > + /* Block new buffers to be queued to CSS. */ > > > > + atomic_set(&imgu->qbuf_barrier, 1); > > > > + /* > > > > +* Wait for currently running irq handler to be done so that > > > > +* no new buffers will be queued to fw later. > > > > +*/ > > > > + synchronize_irq(pci_dev->irq); > > > > + /* Wait until all buffers in CSS are done. */ > > > > + expire = jiffies + msecs_to_jiffies(1000); > > > > + while (!ipu3_css_queue_empty(&imgu->css)) { > > > > + if (time_is_before_jiffies(expire)) { > > > > + dev_err(dev, "wait buffer drain timeout.\n"); > > > > + break; > > > > + } > > > > + } > > > > > > Uhm. We struggle to save some power by suspending the device only to > > > end up with an ugly busy wait that could take even a second here. > > > This doesn't make any sense. > > > > > > We had a working solution using a wait queue in previous revision [1]. > > > What happened to it? > > > > > > [1] https://chromium- > > > > review.googlesource.com/c/chromiumos/third_party/kernel/+/1029594/2 > > > /drivers/media/pci/intel/ipu3/ipu3.c#b913 > > > (see the left side) > > > > > > > The code here was based on an old version of patch "ipu3-imgu: Avoid > might sleep operations in suspend callback" at submission, so it did have > buf_drain_wq, sorry for the confusion. > > > > I guess that means that v7 is going to have the workqueue back? :) > Yes, that's the plan. > Best regards, > Tomasz
RE: [PATCH v6 06/12] intel-ipu3: css: Add support for firmware management
Hi, Sakari, > -Original Message- > From: Sakari Ailus [mailto:sakari.ai...@linux.intel.com] > Sent: Friday, September 21, 2018 6:52 AM > To: Zhi, Yong > Cc: Tomasz Figa ; Linux Media Mailing List me...@vger.kernel.org>; Mani, Rajmohan ; > Toivonen, Tuukka ; Hu, Jerry W > ; Zheng, Jian Xu > Subject: Re: [PATCH v6 06/12] intel-ipu3: css: Add support for firmware > management > > Hi Yong, > > On Wed, Sep 19, 2018 at 10:57:55PM +, Zhi, Yong wrote: > ... > > > > +struct imgu_abi_osys_frame_params { > > > > + /* Output pins */ > > > > + __u32 enable; > > > > + __u32 format; /* enum imgu_abi_osys_format */ > > > > + __u32 flip; > > > > + __u32 mirror; > > > > + __u32 tiling; /* enum imgu_abi_osys_tiling */ > > > > + __u32 width; > > > > + __u32 height; > > > > + __u32 stride; > > > > + __u32 scaled; > > > > +} __packed; > > > [snip] > > > > +/* Defect pixel correction */ > > > > + > > > > +struct imgu_abi_dpc_config { > > > > + __u8 __reserved[240832]; > > > > +} __packed; > > > > > > Do we need this structure? One could just add a reserved field in > > > the parent structure. Also, just to confirm, is 240832 really the right > value here? > > > Where does it come from? Please create a macro for it, possibly > > > further breaking it down into the values used to compute this number. > > > > > > > We can add a reserved field in the parent structure, the size is based > > on original definition of dpc config which was removed since it's not > > enabled/used. > > What's your plan with the DPC? If you don't plan to add it now, you could > as well drop the configuration for that block. If there's a need to add it > later > on, you can still do it by defining a new struct for the buffer. Or simply > adding it at the end of the existing struct while allowing the use of the old > size without the DPC configuration. > > There would be a little extra work to do there by that time when DPC > support would be added, but OTOH it seems silly to have quarter of a > megabyte of extra stuff to pass around in a struct that's never used. > > -- > Regards, > > Sakari Ailus > sakari.ai...@linux.intel.com It's a very good point, but as I was informed, there is no plan to update the abi between the driver and firmware, so the size of imgu_abi_acc_param has not changed since v1 to maintain the compatibility.
RE: [PATCH v6 06/12] intel-ipu3: css: Add support for firmware management
Hi, Tomasz, > -Original Message- > From: linux-media-ow...@vger.kernel.org [mailto:linux-media- > ow...@vger.kernel.org] On Behalf Of Tomasz Figa > Sent: Monday, July 2, 2018 2:05 AM > To: Zhi, Yong > Cc: Linux Media Mailing List ; Sakari Ailus > ; Mani, Rajmohan > ; Toivonen, Tuukka > ; Hu, Jerry W ; Zheng, > Jian Xu > Subject: Re: [PATCH v6 06/12] intel-ipu3: css: Add support for firmware > management > > Hi Yong, > > Continuing my review. Sorry for the delay. > > On Fri, Mar 30, 2018 at 11:15 AM Yong Zhi wrote: > > > > Introduce functions to load and install ImgU FW blobs. > > > > Signed-off-by: Yong Zhi > > --- > > drivers/media/pci/intel/ipu3/ipu3-abi.h| 1888 > > > drivers/media/pci/intel/ipu3/ipu3-css-fw.c | 261 > > drivers/media/pci/intel/ipu3/ipu3-css-fw.h | 198 +++ > > 3 files changed, 2347 insertions(+) > > create mode 100644 drivers/media/pci/intel/ipu3/ipu3-abi.h > > create mode 100644 drivers/media/pci/intel/ipu3/ipu3-css-fw.c > > create mode 100644 drivers/media/pci/intel/ipu3/ipu3-css-fw.h > > > > diff --git a/drivers/media/pci/intel/ipu3/ipu3-abi.h > > b/drivers/media/pci/intel/ipu3/ipu3-abi.h > > new file mode 100644 > > index ..24102647a89e > > --- /dev/null > > +++ b/drivers/media/pci/intel/ipu3/ipu3-abi.h > [snip] > > +/* SYSTEM_REQ_0_5_0_IMGHMMADR */ > > +#define IMGU_REG_SYSTEM_REQ0x18 > > +#define IMGU_SYSTEM_REQ_FREQ_MASK 0x3f > > +#define IMGU_SYSTEM_REQ_FREQ_DIVIDER 25 > > +#define IMGU_REG_INT_STATUS0x30 > > +#define IMGU_REG_INT_ENABLE0x34 > > +#define IMGU_REG_INT_CSS_IRQ (1 << 31) > > BIT(31) > Ack. > [snip] > > + IMGU_ABI_FRAME_FORMAT_CSI_MIPI_LEGACY_YUV420_8, /* > Legacy YUV420. > > +* UY odd line; > > +* VY even line > > +*/ > > + IMGU_ABI_FRAME_FORMAT_CSI_MIPI_YUV420_10,/* 10 bit per > Y/U/V. Y odd > > + * line; UYVY interleaved > > + * even line > > + */ > > + IMGU_ABI_FRAME_FORMAT_YCgCo444_16, /* Internal format for > > + ISP2.7, > > Macros and enums should be uppercase. > Ack. > [snip] > > +struct imgu_abi_shd_intra_frame_operations_data { > > + struct imgu_abi_acc_operation > > + operation_list[IMGU_ABI_SHD_MAX_OPERATIONS] > IPU3_ALIGN; > > + struct imgu_abi_acc_process_lines_cmd_data > > + process_lines_data[IMGU_ABI_SHD_MAX_PROCESS_LINES] > IPU3_ALIGN; > > + struct imgu_abi_shd_transfer_luts_set_data > > + transfer_data[IMGU_ABI_SHD_MAX_TRANSFERS] IPU3_ALIGN; > > +} __packed; > > + > > +struct imgu_abi_shd_config { > > + struct ipu3_uapi_shd_config_static shd IMGU_ABI_PAD; > > + struct imgu_abi_shd_intra_frame_operations_data shd_ops > IMGU_ABI_PAD; > > + struct ipu3_uapi_shd_lut shd_lut IMGU_ABI_PAD; > > Definitions of both IPU3_ALIGN and IMGU_ABI_PAD seem to be equivalent. > Could we remove one and use the other everywhere? > Agree, will remove IMGU_ABI_PAD. > [snip] > > +struct imgu_abi_osys_scaler_params { > > + __u32 inp_buf_y_st_addr; > > + __u32 inp_buf_y_line_stride; > > + __u32 inp_buf_y_buffer_stride; > > + __u32 inp_buf_u_st_addr; > > + __u32 inp_buf_v_st_addr; > > + __u32 inp_buf_uv_line_stride; > > + __u32 inp_buf_uv_buffer_stride; > > + __u32 inp_buf_chunk_width; > > + __u32 inp_buf_nr_buffers; > > + /* Output buffers */ > > + __u32 out_buf_y_st_addr; > > + __u32 out_buf_y_line_stride; > > + __u32 out_buf_y_buffer_stride; > > + __u32 out_buf_u_st_addr; > > + __u32 out_buf_v_st_addr; > > + __u32 out_buf_uv_line_stride; > > + __u32 out_buf_uv_buffer_stride; > > + __u32 out_buf_nr_buffers; > > + /* Intermediate buffers */ > > + __u32 int_buf_y_st_addr; > > + __u32 int_buf_y_line_stride; > > + __u32 int_buf_u_st_addr; > > + __u32 int_buf_v_st_addr; > > + __u32 int_buf_uv_line_stride; > > + __u32 int_buf_height; > > + __u32 int_buf_chunk_width; > &
RE: [PATCH v6 12/12] intel-ipu3: Add imgu top level pci device driver
Hi, Tomasz, Thanks for the code review. > -Original Message- > From: linux-media-ow...@vger.kernel.org [mailto:linux-media- > ow...@vger.kernel.org] On Behalf Of Tomasz Figa > Sent: Monday, July 2, 2018 3:08 AM > To: Zhi, Yong > Cc: Linux Media Mailing List ; Sakari Ailus > ; Mani, Rajmohan > ; Toivonen, Tuukka > ; Hu, Jerry W ; Zheng, > Jian Xu > Subject: Re: [PATCH v6 12/12] intel-ipu3: Add imgu top level pci device > driver > > Hi Yong, > > On Fri, Mar 30, 2018 at 11:15 AM Yong Zhi wrote: > > +/* > > + * Queue as many buffers to CSS as possible. If all buffers don't fit > > +into > > + * CSS buffer queues, they remain unqueued and will be queued later. > > + */ > > +int imgu_queue_buffers(struct imgu_device *imgu, bool initial) { > > + unsigned int node; > > + int r = 0; > > + struct imgu_buffer *ibuf; > > + > > + if (!ipu3_css_is_streaming(&imgu->css)) > > + return 0; > > + > > + mutex_lock(&imgu->lock); > > + > > + /* Buffer set is queued to FW only when input buffer is ready */ > > + if (!imgu_queue_getbuf(imgu, IMGU_NODE_IN)) { > > + mutex_unlock(&imgu->lock); > > + return 0; > > + } > > + for (node = IMGU_NODE_IN + 1; 1; node = (node + 1) % > > + IMGU_NODE_NUM) { > > Shouldn't we make (node != IMGU_NODE_IN || imgu_queue_getbuf(imgu, > IMGU_NODE_IN)) the condition here, rather than 1? > > This would also let us remove the explicit call to imgu_queue_getbuf() > above the loop. > Ack, will make the suggested changes regarding the loop condition evaluation. > > + if (node == IMGU_NODE_VF && > > + (imgu->css.pipe_id == IPU3_CSS_PIPE_ID_CAPTURE || > > +!imgu->nodes[IMGU_NODE_VF].enabled)) { > > + continue; > > + } else if (node == IMGU_NODE_PV && > > + (imgu->css.pipe_id == IPU3_CSS_PIPE_ID_VIDEO || > > + !imgu->nodes[IMGU_NODE_PV].enabled)) { > > + continue; > > + } else if (imgu->queue_enabled[node]) { > > + struct ipu3_css_buffer *buf = > > + imgu_queue_getbuf(imgu, node); > > + int dummy; > > + > > + if (!buf) > > + break; > > + > > + r = ipu3_css_buf_queue(&imgu->css, buf); > > + if (r) > > + break; > > + dummy = imgu_dummybufs_check(imgu, buf); > > + if (!dummy) > > + ibuf = container_of(buf, struct imgu_buffer, > > + css_buf); > > + dev_dbg(&imgu->pci_dev->dev, > > + "queue %s %s buffer %d to css da: 0x%08x\n", > > + dummy ? "dummy" : "user", > > + imgu_node_map[node].name, > > + dummy ? 0 : ibuf->vid_buf.vbb.vb2_buf.index, > > + (u32)buf->daddr); > > + } > > + if (node == IMGU_NODE_IN && > > + !imgu_queue_getbuf(imgu, IMGU_NODE_IN)) > > + break; > > My suggestion to the for loop condition is based on this. > Got it. > > + } > > + mutex_unlock(&imgu->lock); > > + > > + if (r && r != -EBUSY) > > + goto failed; > > + > > + return 0; > > + > > +failed: > > + /* > > +* On error, mark all buffers as failed which are not > > +* yet queued to CSS > > +*/ > > + dev_err(&imgu->pci_dev->dev, > > + "failed to queue buffer to CSS on queue %i (%d)\n", > > + node, r); > > + > > + if (initial) > > + /* If we were called from streamon(), no need to finish > > bufs */ > > + return r; > > + > > + for (node = 0; node < IMGU_NODE_NUM; node++) { > > + struct imgu_buffer *buf, *buf0; > > + > > + if (!imgu->queue_enabled[node]) > > + continue;
RE: [PATCH v6 11/12] intel-ipu3: Add v4l2 driver based on media framework
Hi, Tomasz, Sorry for the delay in responding to your review. > -Original Message- > From: linux-media-ow...@vger.kernel.org [mailto:linux-media- > ow...@vger.kernel.org] On Behalf Of Tomasz Figa > Sent: Monday, July 2, 2018 2:50 AM > To: Zhi, Yong > Cc: Linux Media Mailing List ; Sakari Ailus > ; Mani, Rajmohan > ; Toivonen, Tuukka > ; Hu, Jerry W ; Zheng, > Jian Xu ; Vijaykumar, Ramya > > Subject: Re: [PATCH v6 11/12] intel-ipu3: Add v4l2 driver based on media > framework > > Hi Yong, > > On Fri, Mar 30, 2018 at 11:15 AM Yong Zhi wrote: > [snip] > > +static int ipu3_vidioc_enum_input(struct file *file, void *fh, > > + struct v4l2_input *input) { > > + if (input->index > 0) > > + return -EINVAL; > > + strlcpy(input->name, "camera", sizeof(input->name)); > > + input->type = V4L2_INPUT_TYPE_CAMERA; > > + > > + return 0; > > +} > > + > > +static int ipu3_vidioc_g_input(struct file *file, void *fh, unsigned > > +int *input) { > > + *input = 0; > > + > > + return 0; > > +} > > + > > +static int ipu3_vidioc_s_input(struct file *file, void *fh, unsigned > > +int input) { > > + return input == 0 ? 0 : -EINVAL; } > > + > > +static int ipu3_vidioc_enum_output(struct file *file, void *fh, > > + struct v4l2_output *output) { > > + if (output->index > 0) > > + return -EINVAL; > > + strlcpy(output->name, "camera", sizeof(output->name)); > > + output->type = V4L2_INPUT_TYPE_CAMERA; > > + > > + return 0; > > +} > > + > > +static int ipu3_vidioc_g_output(struct file *file, void *fh, > > + unsigned int *output) { > > + *output = 0; > > + > > + return 0; > > +} > > + > > +static int ipu3_vidioc_s_output(struct file *file, void *fh, > > + unsigned int output) { > > + return output == 0 ? 0 : -EINVAL; } > > Do we really need to implement the 6 functions above? They don't seem to > be doing anything useful. > They are here to pass v4l2-compliance test. I can add a note in next update for their purpose. We can remove them in the future when defaults callbacks are available for those ops. > [snip] > > > +int ipu3_v4l2_register(struct imgu_device *imgu) { > > + struct v4l2_mbus_framefmt def_bus_fmt = { 0 }; > > + struct v4l2_pix_format_mplane def_pix_fmt = { 0 }; > > + > > + int i, r; > > + > > + /* Initialize miscellaneous variables */ > > + imgu->streaming = false; > > + > > + /* Set up media device */ > > + imgu->media_dev.dev = &imgu->pci_dev->dev; > > + strlcpy(imgu->media_dev.model, IMGU_NAME, > > + sizeof(imgu->media_dev.model)); > > + snprintf(imgu->media_dev.bus_info, sizeof(imgu- > >media_dev.bus_info), > > +"%s", dev_name(&imgu->pci_dev->dev)); > > + imgu->media_dev.hw_revision = 0; > > + media_device_init(&imgu->media_dev); > > + r = media_device_register(&imgu->media_dev); > > + if (r) { > > + dev_err(&imgu->pci_dev->dev, > > + "failed to register media device (%d)\n", r); > > + return r; > > + } > > Shouldn't we register the media device at the end, after all video nodes are > registered below? Otherwise, since media_device_register() exposes the > media node to userspace, we risk a race, when userspace opens the media > device before all the entities are created and linked. > Make sense, will change the call order in v7. > [snip] > > > +int ipu3_v4l2_unregister(struct imgu_device *imgu) { > > + unsigned int i; > > + > > + for (i = 0; i < IMGU_NODE_NUM; i++) { > > + video_unregister_device(&imgu->nodes[i].vdev); > > + media_entity_cleanup(&imgu->nodes[i].vdev.entity); > > + mutex_destroy(&imgu->nodes[i].lock); > > + } > > + > > + v4l2_device_unregister_subdev(&imgu->subdev); > > + media_entity_cleanup(&imgu->subdev.entity); > > + kfree(imgu->subdev_pads); > > + v4l2_device_unregister(&imgu->v4l2_dev); > > + media_device_unregister(&imgu->media_dev); > > Should unregister media device at the beginning, so that it cannot be used > when we continue to clean up the entities. > Agree, thanks for the review. > > + media_device_cleanup(&imgu->media_dev); > > + > > + return 0; > > +} > > +EXPORT_SYMBOL_GPL(ipu3_v4l2_unregister); > > Best regards, > Tomasz
Re: [PATCH v10 2/2] media: V3s: Add support for Allwinner CSI.
Hi Sakari, On Wed, 18 Jul 2018 12:55:14 +0300 Sakari Ailus wrote: > Hi Yong, > > On Thu, Jul 05, 2018 at 03:48:02PM +0800, Yong wrote: > > > > + > > > > +/* > > > > - > > > > + * Media Operations > > > > + */ > > > > +static int sun6i_video_formats_init(struct sun6i_video *video, > > > > + const struct media_pad *remote) > > > > +{ > > > > + struct v4l2_subdev_mbus_code_enum mbus_code = { 0 }; > > > > + struct sun6i_csi *csi = video->csi; > > > > + struct v4l2_format format; > > > > + struct v4l2_subdev *subdev; > > > > + u32 pad; > > > > + const u32 *pixformats; > > > > + int pixformat_count = 0; > > > > + u32 subdev_codes[32]; /* subdev format codes, 32 should be > > > > enough */ > > > > + int codes_count = 0; > > > > + int num_fmts = 0; > > > > + int i, j; > > > > + > > > > + pad = remote->index; > > > > + subdev = media_entity_to_v4l2_subdev(remote->entity); > > > > + if (subdev == NULL) > > > > + return -ENXIO; > > > > + > > > > + /* Get supported pixformats of CSI */ > > > > + pixformat_count = sun6i_csi_get_supported_pixformats(csi, > > > > &pixformats); > > > > + if (pixformat_count <= 0) > > > > + return -ENXIO; > > > > + > > > > + /* Get subdev formats codes */ > > > > + mbus_code.pad = pad; > > > > + mbus_code.which = V4L2_SUBDEV_FORMAT_ACTIVE; > > > > + while (!v4l2_subdev_call(subdev, pad, enum_mbus_code, NULL, > > > > +&mbus_code)) { > > > > > > The formats supported by the external sub-device may depend on horizontal > > > and vertical flipping. You shouldn't assume any particular configuration > > > here: instead, bridge drivers generally just need to make sure the formats > > > match in link validation when streaming is started. At least the CSI-2 > > > receiver driver and the DMA engine driver (video device) should check the > > > configuration is valid. See e.g. the IPU3 driver: > > > drivers/media/pci/intel/ipu3/ipu3-cio2.c . > > > > Can mbus_code be added dynamically ? > > The code here only enum the mbus code and get the possible supported > > pairs of pixformat and mbus by SoC. Not try to check if the formats > > (width height ...) is valid or not. The formats validation will be > > in link validation when streaming is started as per your advise. > > The formats that can be enumerated from the sensor here are those settable > using SUBDEV_S_FMT. The enumeration will change on raw sensors if you use > the flipping controls. As the bridge driver implements MC as well as subdev > APIs, generally the sensor configuration is out of scope of this driver > since it's directly configured from the user space. > > Just check that the pipeline is valid before starting streaming in your > driver. Sorry. I am still confused. As the CSI driver does not enum the formats supported by sensor. How to get a valid format if I do not want to open the subdev? Many applications still only open /dev/video*. > > -- > Kind regards, > > Sakari Ailus > sakari.ai...@linux.intel.com Thanks, Yong
RE: [PATCH v6 02/12] intel-ipu3: Add user space API definitions
Hi, Tomasz, Thank you for the time spent to review this long file. > -Original Message- > From: Tomasz Figa [mailto:tf...@chromium.org] > Sent: Sunday, June 17, 2018 11:09 PM > To: Zhi, Yong > Cc: Linux Media Mailing List ; Sakari Ailus > ; Mani, Rajmohan > ; Toivonen, Tuukka > ; Hu, Jerry W ; Zheng, > Jian Xu > Subject: Re: [PATCH v6 02/12] intel-ipu3: Add user space API definitions > > Hi Yong, > > On Fri, Mar 30, 2018 at 11:15 AM Yong Zhi wrote: > > > > Define the structures and macros to be used by public. > > > > Signed-off-by: Yong Zhi > > Signed-off-by: Rajmohan Mani > > --- > > include/uapi/linux/intel-ipu3.h | 1403 > > +++ > > 1 file changed, 1403 insertions(+) > > create mode 100644 include/uapi/linux/intel-ipu3.h > > > > Since we'll need 1 more resend with latest fixes from Chromium tree and > recently posted documentation anyway, let me do some more nitpicking > inline, so we can end up with slightly cleaner code. :) > > > diff --git a/include/uapi/linux/intel-ipu3.h > > b/include/uapi/linux/intel-ipu3.h new file mode 100644 index > > ..694ef0c8d7a7 > > --- /dev/null > > +++ b/include/uapi/linux/intel-ipu3.h > > @@ -0,0 +1,1403 @@ > > +/* SPDX-License-Identifier: GPL-2.0 */ > > +/* Copyright (C) 2018 Intel Corporation */ > > + > > +#ifndef __IPU3_UAPI_H > > +#define __IPU3_UAPI_H > > + > > +#include > > + > > +#define IPU3_UAPI_ISP_VEC_ELEMS64 > > + > > +#define IMGU_ABI_PAD __aligned(IPU3_UAPI_ISP_WORD_BYTES) > > This seems unused. Ack, will remove. > > > +#define IPU3_ALIGN > __attribute__((aligned(IPU3_UAPI_ISP_WORD_BYTES))) > > Any reason to mix both __aligned() and __attribute__((aligned()))? > > > + > > +#define IPU3_UAPI_ISP_WORD_BYTES 32 > > It would make sense to define this above IPU3_ALIGN(), which references it. > Sure. > > +#define IPU3_UAPI_MAX_STRIPES 2 > > + > > +/*** ipu3_uapi_stats_3a ***/ > > + > > +#define IPU3_UAPI_MAX_BUBBLE_SIZE 10 > > + > > +#define IPU3_UAPI_AE_COLORS4 > > +#define IPU3_UAPI_AE_BINS 256 > > + > > +#define IPU3_UAPI_AWB_MD_ITEM_SIZE 8 > > +#define IPU3_UAPI_AWB_MAX_SETS 60 > > +#define IPU3_UAPI_AWB_SET_SIZE 0x500 > > Why not just decimal 1280? Ok, will change above and similar places to decimal expression. > > > +#define IPU3_UAPI_AWB_SPARE_FOR_BUBBLES \ > > + (IPU3_UAPI_MAX_BUBBLE_SIZE * IPU3_UAPI_MAX_STRIPES * \ > > +IPU3_UAPI_AWB_MD_ITEM_SIZE) > > +#define IPU3_UAPI_AWB_MAX_BUFFER_SIZE \ > > + (IPU3_UAPI_AWB_MAX_SETS * \ > > +(IPU3_UAPI_AWB_SET_SIZE + > IPU3_UAPI_AWB_SPARE_FOR_BUBBLES)) > > + > > +#define IPU3_UAPI_AF_MAX_SETS 24 > > +#define IPU3_UAPI_AF_MD_ITEM_SIZE 4 > > +#define IPU3_UAPI_AF_SPARE_FOR_BUBBLES \ > > + (IPU3_UAPI_MAX_BUBBLE_SIZE * IPU3_UAPI_MAX_STRIPES * \ > > +IPU3_UAPI_AF_MD_ITEM_SIZE) > > +#define IPU3_UAPI_AF_Y_TABLE_SET_SIZE 0x80 > > Why not just decimal 128? Ack. > > > +#define IPU3_UAPI_AF_Y_TABLE_MAX_SIZE \ > > + (IPU3_UAPI_AF_MAX_SETS * \ > > +(IPU3_UAPI_AF_Y_TABLE_SET_SIZE + > IPU3_UAPI_AF_SPARE_FOR_BUBBLES) * \ > > +IPU3_UAPI_MAX_STRIPES) > > + > > +#define IPU3_UAPI_AWB_FR_MAX_SETS 24 > > +#define IPU3_UAPI_AWB_FR_MD_ITEM_SIZE 8 > > +#define IPU3_UAPI_AWB_FR_BAYER_TBL_SIZE0x100 > > Why not just decimal 256? Ack. > > > +#define IPU3_UAPI_AWB_FR_SPARE_FOR_BUBBLES \ > > + (IPU3_UAPI_MAX_BUBBLE_SIZE * IPU3_UAPI_MAX_STRIPES * \ > > +IPU3_UAPI_AWB_FR_MD_ITEM_SIZE) #define > > +IPU3_UAPI_AWB_FR_BAYER_TABLE_MAX_SIZE \ > > + (IPU3_UAPI_AWB_FR_MAX_SETS * \ > > + (IPU3_UAPI_AWB_FR_BAYER_TBL_SIZE + \ > > +IPU3_UAPI_AWB_FR_SPARE_FOR_BUBBLES) * > IPU3_UAPI_MAX_STRIPES) > [snip] > > +struct ipu3_uapi_af_filter_config { > > + struct { > > + __u8 a1; > > + __u8 a2; > > + __u8 a3; > > + __u8 a4; > > + } y1_coeff_0; > > + struct { > > + __u8 a5; > > + __u8 a6; &g
RE: [PATCH v6 04/12] intel-ipu3: Implement DMA mapping functions
Hi, Tomasz, Thanks for the review. > -Original Message- > From: Tomasz Figa [mailto:tf...@chromium.org] > Sent: Monday, June 18, 2018 12:09 AM > To: Zhi, Yong > Cc: Linux Media Mailing List ; Sakari Ailus > ; Mani, Rajmohan > ; Toivonen, Tuukka > ; Hu, Jerry W ; Zheng, > Jian Xu > Subject: Re: [PATCH v6 04/12] intel-ipu3: Implement DMA mapping > functions > > On Fri, Mar 30, 2018 at 11:15 AM Yong Zhi wrote: > > > > From: Tomasz Figa > > > > This driver uses IOVA space for buffer mapping through IPU3 MMU to > > transfer data between imaging pipelines and system DDR. > > > > Signed-off-by: Tomasz Figa > > Signed-off-by: Yong Zhi > > --- > > drivers/media/pci/intel/ipu3/ipu3-css-pool.h | 36 > > drivers/media/pci/intel/ipu3/ipu3-dmamap.c | 280 > +++ > > drivers/media/pci/intel/ipu3/ipu3-dmamap.h | 22 +++ > > drivers/media/pci/intel/ipu3/ipu3.h | 151 +++ > > 4 files changed, 489 insertions(+) > > create mode 100644 drivers/media/pci/intel/ipu3/ipu3-css-pool.h > > create mode 100644 drivers/media/pci/intel/ipu3/ipu3-dmamap.c > > create mode 100644 drivers/media/pci/intel/ipu3/ipu3-dmamap.h > > create mode 100644 drivers/media/pci/intel/ipu3/ipu3.h > > > > diff --git a/drivers/media/pci/intel/ipu3/ipu3-css-pool.h > > b/drivers/media/pci/intel/ipu3/ipu3-css-pool.h > > new file mode 100644 > > index ..4b22e0856232 > > --- /dev/null > > +++ b/drivers/media/pci/intel/ipu3/ipu3-css-pool.h > > @@ -0,0 +1,36 @@ > > +/* SPDX-License-Identifier: GPL-2.0 */ > > +/* Copyright (C) 2018 Intel Corporation */ > > + > > +#ifndef __IPU3_UTIL_H > > +#define __IPU3_UTIL_H > > + > > +struct device; > > + > > +#define IPU3_CSS_POOL_SIZE 4 > > + > > +struct ipu3_css_map { > > + size_t size; > > + void *vaddr; > > + dma_addr_t daddr; > > + struct vm_struct *vma; > > +}; > > + > > +struct ipu3_css_pool { > > + struct { > > + struct ipu3_css_map param; > > + long framenum; > > + } entry[IPU3_CSS_POOL_SIZE]; > > + unsigned int last; /* Latest entry */ > > It's not clear what "Latest entry" means here. Since these structs are a part > of the interface exposed by this header, could you write proper kerneldoc > comments for all fields in both of them? > Sure. > > +}; > > + > > +int ipu3_css_dma_buffer_resize(struct device *dev, struct ipu3_css_map > *map, > > + size_t size); void > > +ipu3_css_pool_cleanup(struct device *dev, struct ipu3_css_pool > > +*pool); int ipu3_css_pool_init(struct device *dev, struct ipu3_css_pool > *pool, > > + size_t size); > > +int ipu3_css_pool_get(struct ipu3_css_pool *pool, long framenum); > > +void ipu3_css_pool_put(struct ipu3_css_pool *pool); const struct > > +ipu3_css_map *ipu3_css_pool_last(struct ipu3_css_pool *pool, > > + unsigned int last); > > + > > +#endif > > diff --git a/drivers/media/pci/intel/ipu3/ipu3-dmamap.c > > b/drivers/media/pci/intel/ipu3/ipu3-dmamap.c > > new file mode 100644 > > index ..b2bc5d00debc > > --- /dev/null > > +++ b/drivers/media/pci/intel/ipu3/ipu3-dmamap.c > > @@ -0,0 +1,280 @@ > > +// SPDX-License-Identifier: GPL-2.0 > > +/* > > + * Copyright (C) 2018 Intel Corporation > > + * Copyright (C) 2018 Google, Inc. > > Would you mind changing as below? > > Copyright 2018 Google LLC. > Ack. > > + * > > + * Author: Tomasz Figa > > + * Author: Yong Zhi */ > > + > > +#include > > + > > +#include "ipu3.h" > > +#include "ipu3-css-pool.h" > > +#include "ipu3-mmu.h" > > + > > +/* > > + * Free a buffer allocated by ipu3_dmamap_alloc_buffer() */ static > > +void ipu3_dmamap_free_buffer(struct page **pages, > > + size_t size) { > > + int count = size >> PAGE_SHIFT; > > + > > + while (count--) > > + __free_page(pages[count]); > > + kvfree(pages); > > +} > > + > > +/* > > + * Based on the implementation of __iommu_dma_alloc_pages() > > + * defined in drivers/iommu/dma-iommu.c */ static struct page > > +**ipu3_dmamap_alloc_buffer(size_t size, > > + unsigned long order_mask, > > +
RE: [PATCH v6 03/12] intel-ipu3: mmu: Implement driver
Hi, Tomasz, Thanks for the code review. > -Original Message- > From: Tomasz Figa [mailto:tf...@chromium.org] > Sent: Sunday, June 17, 2018 11:46 PM > To: Zhi, Yong > Cc: Linux Media Mailing List ; Sakari Ailus > ; Mani, Rajmohan > ; Toivonen, Tuukka > ; Hu, Jerry W ; Zheng, > Jian Xu > Subject: Re: [PATCH v6 03/12] intel-ipu3: mmu: Implement driver > > On Fri, Mar 30, 2018 at 11:15 AM Yong Zhi wrote: > > > > From: Tomasz Figa > > > > This driver translates IO virtual address to physical address based on > > two levels page tables. > > > > Signed-off-by: Tomasz Figa > > Signed-off-by: Yong Zhi > > --- > > drivers/media/pci/intel/ipu3/ipu3-mmu.c | 560 > > > > drivers/media/pci/intel/ipu3/ipu3-mmu.h | 28 ++ > > 2 files changed, 588 insertions(+) > > create mode 100644 drivers/media/pci/intel/ipu3/ipu3-mmu.c > > create mode 100644 drivers/media/pci/intel/ipu3/ipu3-mmu.h > > > > diff --git a/drivers/media/pci/intel/ipu3/ipu3-mmu.c > > b/drivers/media/pci/intel/ipu3/ipu3-mmu.c > > new file mode 100644 > > index ..a4b3e1680bbb > > --- /dev/null > > +++ b/drivers/media/pci/intel/ipu3/ipu3-mmu.c > > @@ -0,0 +1,560 @@ > > +// SPDX-License-Identifier: GPL-2.0 > > +/* > > + * Copyright (c) 2018 Intel Corporation. > > + * Copyright (C) 2018 Google, Inc. > > I followed wrong guide when adding this one. Could you fix it up to the > following? > > Copyright 2018 Google LLC. > Sure, will do. > [snip] > > +/** > > + * ipu3_mmu_exit() - clean up IPU3 MMU block > > + * @mmu: IPU3 MMU private data > > + */ > > +void ipu3_mmu_exit(struct ipu3_mmu_info *info) { > > + struct ipu3_mmu *mmu = to_ipu3_mmu(info); > > + > > + /* We are going to free our page tables, no more memory access. */ > > + ipu3_mmu_set_halt(mmu, true); > > + ipu3_mmu_tlb_invalidate(mmu); > > + > > + ipu3_mmu_free_page_table(mmu->l1pt); > > + vfree(mmu->l2pts); > > + ipu3_mmu_free_page_table(mmu->dummy_l2pt); > > + kfree(mmu->dummy_page); > > Should be free_page(). (Might be already included in your tree as per > https://chromium- > review.googlesource.com/c/chromiumos/third_party/kernel/+/1084522) > Yes, will add above fix to next upstream version. > > + kfree(mmu); > > +} > > + > > +void ipu3_mmu_suspend(struct ipu3_mmu_info *info) { > > + struct ipu3_mmu *mmu = to_ipu3_mmu(info); > > + > > + ipu3_mmu_set_halt(mmu, true); > > +} > > + > > +void ipu3_mmu_resume(struct ipu3_mmu_info *info) { > > + struct ipu3_mmu *mmu = to_ipu3_mmu(info); > > + u32 pteval; > > + > > + ipu3_mmu_set_halt(mmu, true); > > + > > + pteval = IPU3_ADDR2PTE(virt_to_phys(mmu->l1pt)); > > + writel(pteval, mmu->base + REG_L1_PHYS); > > + > > + ipu3_mmu_tlb_invalidate(mmu); > > + ipu3_mmu_set_halt(mmu, false); } > > diff --git a/drivers/media/pci/intel/ipu3/ipu3-mmu.h > > b/drivers/media/pci/intel/ipu3/ipu3-mmu.h > > new file mode 100644 > > index ..4976187c18f6 > > --- /dev/null > > +++ b/drivers/media/pci/intel/ipu3/ipu3-mmu.h > > @@ -0,0 +1,28 @@ > > +/* SPDX-License-Identifier: GPL-2.0 */ > > +/* Copyright (C) 2018 Intel Corporation */ > > +/* Copyright (C) 2018 Google, Inc. */ > > + > > +#ifndef __IPU3_MMU_H > > +#define __IPU3_MMU_H > > + > > +struct ipu3_mmu_info { > > + dma_addr_t aperture_start; /* First address that can be mapped > */ > > + dma_addr_t aperture_end; /* Last address that can be mapped > */ > > + unsigned long pgsize_bitmap;/* Bitmap of page sizes in use */ > > If documenting the fields, why not use a kerneldoc comment above the > struct instead? > Ack. > Best regards, > Tomasz
[PATCH v1 0/2] Document Intel IPU3 ImgU driver and uAPI
Hi, All, This patch set adds documentation on Intel IPU3 ImgU driver and its uAPI, based on the feedback received for v1 RFC below and ImgU driver patch series: v1 RFC: https://patchwork.kernel.org/patch/10321897/> ImgU v6: https://patchwork.kernel.org/patch/10316739/> Few unused structs have being removed from intel-ipu3.h since v6. This patch set will be merged into the next ImgU driver update. Rajmohan Mani (1): doc-rst: Add Intel IPU3 documentation Yong Zhi (1): v4l: Document Intel IPU3 meta data uAPI Documentation/media/uapi/v4l/meta-formats.rst |1 + .../media/uapi/v4l/pixfmt-meta-intel-ipu3.rst | 174 ++ Documentation/media/v4l-drivers/index.rst |1 + Documentation/media/v4l-drivers/ipu3.rst | 304 +++ include/uapi/linux/intel-ipu3.h| 2816 5 files changed, 3296 insertions(+) create mode 100644 Documentation/media/uapi/v4l/pixfmt-meta-intel-ipu3.rst create mode 100644 Documentation/media/v4l-drivers/ipu3.rst create mode 100644 include/uapi/linux/intel-ipu3.h -- 2.7.4
[PATCH v1 1/2] doc-rst: Add Intel IPU3 documentation
From: Rajmohan Mani This patch adds the details about the IPU3 Imaging Unit driver. Signed-off-by: Rajmohan Mani Signed-off-by: Tian Shu Qiu --- Documentation/media/v4l-drivers/index.rst | 1 + Documentation/media/v4l-drivers/ipu3.rst | 304 ++ 2 files changed, 305 insertions(+) create mode 100644 Documentation/media/v4l-drivers/ipu3.rst diff --git a/Documentation/media/v4l-drivers/index.rst b/Documentation/media/v4l-drivers/index.rst index 679238e..179a393 100644 --- a/Documentation/media/v4l-drivers/index.rst +++ b/Documentation/media/v4l-drivers/index.rst @@ -44,6 +44,7 @@ For more details see the file COPYING in the source distribution of Linux. davinci-vpbe fimc imx + ipu3 ivtv max2175 meye diff --git a/Documentation/media/v4l-drivers/ipu3.rst b/Documentation/media/v4l-drivers/ipu3.rst new file mode 100644 index 000..a4550d8 --- /dev/null +++ b/Documentation/media/v4l-drivers/ipu3.rst @@ -0,0 +1,304 @@ +.. include:: + +=== +Intel Image Processing Unit 3 (IPU3) Imaging Unit (ImgU) driver +=== + +Copyright |copy| 2018 Intel Corporation + +Introduction + + +This file documents Intel IPU3 (3rd generation Image Processing Unit) Imaging +Unit driver located under drivers/media/pci/intel/ipu3. + +The Intel IPU3 found in certain Kaby Lake (as well as certain Sky Lake) +platforms (U/Y processor lines) is made up of two parts namely Imaging Unit +(ImgU) and CIO2 device (MIPI CSI2 receiver). + +The CIO2 device receives the raw bayer data from the sensors and outputs the +frames in a format that is specific to IPU3 (for consumption by IPU3 ImgU). +CIO2 driver is available as drivers/media/pci/intel/ipu3/ipu3-cio2* and is +enabled through the CONFIG_VIDEO_IPU3_CIO2 config option. + +The Imaging Unit (ImgU) is responsible for processing images captured +through IPU3 CIO2 device. The ImgU driver sources can be found under +drivers/media/pci/intel/ipu3 directory. The driver is enabled through the +CONFIG_VIDEO_IPU3_IMGU config option. + +The two driver modules are named ipu3-csi2 and ipu3-imgu, respectively. + +The driver has been tested on Kaby Lake platforms (U/Y processor lines). + +The driver implements V4L2, Media controller and V4L2 sub-device interfaces. +Camera sensors that have CSI-2 bus, which are connected to the IPU3 CIO2 +device are supported. Support for lens and flash drivers depends on the +above sensors. + +ImgU device nodes += + +The ImgU is represented as a single V4L2 subdev, which provides a V4L2 subdev +interface to the user space. + +CIO2 device +=== + +The CIO2 is represented as a single V4L2 subdev, which provides a V4L2 subdev +interface to the user space. There is a video node for each CSI-2 receiver, +with a single media controller interface for the entire device. + +Media controller + + +The media device interface allows to configure the ImgU links, which defines +the behavior of the IPU3 firmware. The link configuration tells the firmware +whether viewfinder or postview ISP pipeline should be enabled. + +Device operation + + +With IPU3, once the input video node ("ipu3-imgu":0, in : +format) is queued with buffer (in packed raw bayer format), IPU3 ISP starts +processing the buffer and produces the video output in YUV format and +statistics output on respective output nodes. The driver is expected to have +buffers ready for all of parameter, output and statistics nodes, when input +video node is queued with buffer. + +At a minimum, all of input, main output, 3A statistics, and either of +viewfinder or postview video nodes should be enabled for IPU3 to start image +processing. viewfinder and postview video nodes are mutually exclusive. + +input, output, viewfinder and postview video nodes +-- + +The frames (in packed raw bayer format specific to IPU3) received by the +input video node is processed by the IPU3 Imaging Unit and is output to 2 +video nodes, with each targeting different purpose (main output and viewfinder +or postview output). + +Details on raw bayer format specific to IPU3 can be found as below. +Documentation/media/uapi/v4l/pixfmt-meta-intel-ipu3.rst + +The driver supports V4L2 Video Capture Interface as defined at :ref:`devices`. + +Only the multi-planar API is supported. More details can be found at +:ref:`planar-apis`. + + +parameters video node +- + +The parameter video node receives the ISP algorithm parameters that are used +to configure how the ISP algorithms process the image. + +Details on raw bayer format specific to IPU3 can be found as below. +Documentation/media/uapi/v4l/pixfmt-meta-intel-ipu3.rst + +3A statistics video node + + +3A statistics video node is used by the ImgU driver to out
[PATCH v1 2/2] v4l: Document Intel IPU3 meta data uAPI
These meta formats are used on Intel IPU3 ImgU video queues to carry 3A statistics and ISP pipeline parameters. V4L2_META_FMT_IPU3_3A V4L2_META_FMT_IPU3_PARAMS Signed-off-by: Yong Zhi Signed-off-by: Chao C Li Signed-off-by: Rajmohan Mani --- Documentation/media/uapi/v4l/meta-formats.rst |1 + .../media/uapi/v4l/pixfmt-meta-intel-ipu3.rst | 174 ++ include/uapi/linux/intel-ipu3.h| 2816 3 files changed, 2991 insertions(+) create mode 100644 Documentation/media/uapi/v4l/pixfmt-meta-intel-ipu3.rst create mode 100644 include/uapi/linux/intel-ipu3.h diff --git a/Documentation/media/uapi/v4l/meta-formats.rst b/Documentation/media/uapi/v4l/meta-formats.rst index 0c4e1ec..b887fca 100644 --- a/Documentation/media/uapi/v4l/meta-formats.rst +++ b/Documentation/media/uapi/v4l/meta-formats.rst @@ -12,6 +12,7 @@ These formats are used for the :ref:`metadata` interface only. .. toctree:: :maxdepth: 1 +pixfmt-meta-intel-ipu3 pixfmt-meta-uvc pixfmt-meta-vsp1-hgo pixfmt-meta-vsp1-hgt diff --git a/Documentation/media/uapi/v4l/pixfmt-meta-intel-ipu3.rst b/Documentation/media/uapi/v4l/pixfmt-meta-intel-ipu3.rst new file mode 100644 index 000..5c050e6 --- /dev/null +++ b/Documentation/media/uapi/v4l/pixfmt-meta-intel-ipu3.rst @@ -0,0 +1,174 @@ +.. -*- coding: utf-8; mode: rst -*- + +.. _intel-ipu3: + +** +V4L2_META_FMT_IPU3_PARAMS ('ip3p'), V4L2_META_FMT_IPU3_3A ('ip3s') +** + +.. c:type:: ipu3_uapi_stats_3a + +3A statistics += + +For IPU3 ImgU, the 3A statistics accelerators collect different statistics over +an input bayer frame. Those statistics, defined in data struct +:c:type:`ipu3_uapi_stats_3a`, are meta output obtained from "ipu3-imgu 3a stat" +video node, which are then passed to user space for statistics analysis +using :c:type:`v4l2_meta_format` interface. + +The statistics collected are AWB (Auto-white balance) RGBS cells, AWB filter +response, AF (Auto-focus) filter response, and AE (Auto-exposure) histogram. + +struct :c:type:`ipu3_uapi_4a_config` saves configurable parameters for all above. + + +.. code-block:: c + + + struct ipu3_uapi_stats_3a { + IPU3_ALIGN struct ipu3_uapi_awb_raw_buffer awb_raw_buffer; + struct ipu3_uapi_ae_raw_buffer_aligned + ae_raw_buffer[IPU3_UAPI_MAX_STRIPES]; + struct ipu3_uapi_af_raw_buffer af_raw_buffer; + struct ipu3_uapi_awb_fr_raw_buffer awb_fr_raw_buffer; + struct ipu3_uapi_4a_config stats_4a_config; + __u32 ae_join_buffers; + __u8 padding[28]; + struct ipu3_uapi_stats_3a_bubble_info_per_stripe + stats_3a_bubble_per_stripe; + struct ipu3_uapi_ff_status stats_3a_status; + } __packed; + + +.. c:type:: ipu3_uapi_params + +Pipeline parameters +=== + +IPU3 pipeline has a number of image processing stages, each of which takes a +set of parameters as input. The major stages of pipelines are shown here: + +Raw pixels -> Bayer Downscaling -> Optical Black Correction -> + +Linearization -> Lens Shading Correction -> White Balance / Exposure / + +Focus Apply -> Bayer Noise Reduction -> ANR -> Demosaicing -> Color + +Correction Matrix -> Gamma correction -> Color Space Conversion -> + +Chroma Down Scaling -> Chromatic Noise Reduction -> Total Color + +Correction -> XNR3 -> TNR -> DDR + +The table below presents a description of the above algorithms. + + === +NameDescription + === +Optical Black Correction Optical Black Correction block subtracts a pre-defined +value from the respective pixel values to obtain better +image quality. +Defined in :c:type:`ipu3_uapi_obgrid_param`. +Linearization This algo block uses linearization parameters to +address non-linearity sensor effects. The Lookup table +table is defined in +:c:type:`ipu3_uapi_isp_lin_vmem_params`. +SHD Lens shading correction is used to correct spatial +non-uniformity of the pixel response due to optical +lens shading. This is done by applying a different gain +for each pixel. The gain, black level etc are +configured in :c:type:`ipu3_uapi_shd_config_static`. +BNR Bayer noise reduction block removes image noise by +applying a bilateral filter. +See :c:type:`ipu3_uapi_bnr_static_config` for deta
[PATCH v3] [media] MAINTAINERS: Update entry for Intel IPU3 cio2 driver
This patch adds Bingbu as additional maintainer, and both Tian Shu and Jian Xu as reviewers for IPU3 CIO2 driver. Signed-off-by: Yong Zhi --- Third time's a charm :) MAINTAINERS | 3 +++ 1 file changed, 3 insertions(+) diff --git a/MAINTAINERS b/MAINTAINERS index a38e24a..3dd530e 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -7157,6 +7157,9 @@ F:drivers/dma/iop-adma.c INTEL IPU3 CSI-2 CIO2 DRIVER M: Yong Zhi M: Sakari Ailus +M: Bingbu Cao +R: Tian Shu Qiu +R: Jian Xu Zheng L: linux-media@vger.kernel.org S: Maintained F: drivers/media/pci/intel/ipu3/ -- 2.7.4
[PATCH v2] [media] MAINTAINERS: Update entry for Intel IPU3 cio2 driver
This patch adds three more maintainers to the IPU3 CIO2 driver. Signed-off-by: Yong Zhi --- MAINTAINERS | 3 +++ 1 file changed, 3 insertions(+) diff --git a/MAINTAINERS b/MAINTAINERS index a38e24a..3dd530e 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -7157,6 +7157,9 @@ F:drivers/dma/iop-adma.c INTEL IPU3 CSI-2 CIO2 DRIVER M: Yong Zhi M: Sakari Ailus +M: Bingbu Cao +R: Tian Shu Qiu +R: Jian Xu Zheng L: linux-media@vger.kernel.org S: Maintained F: drivers/media/pci/intel/ipu3/ -- 2.7.4
[PATCH] [media] MAINTAINERS: Update entry for Intel IPU3 cio2 driver
This patch adds three more maintainers to the IPU3 CIO2 driver. Signed-off-by: Yong Zhi --- MAINTAINERS | 3 +++ 1 file changed, 3 insertions(+) diff --git a/MAINTAINERS b/MAINTAINERS index 49003f77cedd..309d49a54db8 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -7150,6 +7150,9 @@ F:drivers/dma/iop-adma.c INTEL IPU3 CSI-2 CIO2 DRIVER M: Yong Zhi M: Sakari Ailus +M: Tian Shu Qiu +M: Bingbu Cao +M: Jian Xu Zheng L: linux-media@vger.kernel.org S: Maintained F: drivers/media/pci/intel/ipu3/ -- 2.7.4
[PATCH v10 2/2] media: V3s: Add support for Allwinner CSI.
Allwinner V3s SoC features two CSI module. CSI0 is used for MIPI CSI-2 interface and CSI1 is used for parallel interface. This is not documented in datasheet but by test and guess. This patch implement a v4l2 framework driver for it. Currently, the driver only support the parallel interface. MIPI-CSI2, ISP's support are not included in this patch. Reviewed-by: Hans Verkuil Reviewed-by: Maxime Ripard Tested-by: Maxime Ripard Signed-off-by: Yong Deng --- MAINTAINERS| 8 + drivers/media/platform/Kconfig | 1 + drivers/media/platform/Makefile| 2 + drivers/media/platform/sunxi/sun6i-csi/Kconfig | 9 + drivers/media/platform/sunxi/sun6i-csi/Makefile| 3 + drivers/media/platform/sunxi/sun6i-csi/sun6i_csi.c | 932 + drivers/media/platform/sunxi/sun6i-csi/sun6i_csi.h | 145 .../media/platform/sunxi/sun6i-csi/sun6i_csi_reg.h | 196 + .../media/platform/sunxi/sun6i-csi/sun6i_video.c | 767 + .../media/platform/sunxi/sun6i-csi/sun6i_video.h | 53 ++ 10 files changed, 2116 insertions(+) create mode 100644 drivers/media/platform/sunxi/sun6i-csi/Kconfig create mode 100644 drivers/media/platform/sunxi/sun6i-csi/Makefile create mode 100644 drivers/media/platform/sunxi/sun6i-csi/sun6i_csi.c create mode 100644 drivers/media/platform/sunxi/sun6i-csi/sun6i_csi.h create mode 100644 drivers/media/platform/sunxi/sun6i-csi/sun6i_csi_reg.h create mode 100644 drivers/media/platform/sunxi/sun6i-csi/sun6i_video.c create mode 100644 drivers/media/platform/sunxi/sun6i-csi/sun6i_video.h diff --git a/MAINTAINERS b/MAINTAINERS index 0a1410d5a621..a8f9fe91dd14 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -3771,6 +3771,14 @@ M: Jaya Kumar S: Maintained F: sound/pci/cs5535audio/ +CSI DRIVERS FOR ALLWINNER V3s +M: Yong Deng +L: linux-media@vger.kernel.org +T: git git://linuxtv.org/media_tree.git +S: Maintained +F: drivers/media/platform/sunxi/sun6i-csi/ +F: Documentation/devicetree/bindings/media/sun6i-csi.txt + CW1200 WLAN driver M: Solomon Peachy S: Maintained diff --git a/drivers/media/platform/Kconfig b/drivers/media/platform/Kconfig index e3229f7baed1..43f25c9c05e1 100644 --- a/drivers/media/platform/Kconfig +++ b/drivers/media/platform/Kconfig @@ -138,6 +138,7 @@ source "drivers/media/platform/am437x/Kconfig" source "drivers/media/platform/xilinx/Kconfig" source "drivers/media/platform/rcar-vin/Kconfig" source "drivers/media/platform/atmel/Kconfig" +source "drivers/media/platform/sunxi/sun6i-csi/Kconfig" config VIDEO_TI_CAL tristate "TI CAL (Camera Adaptation Layer) driver" diff --git a/drivers/media/platform/Makefile b/drivers/media/platform/Makefile index 932515df4477..69472cbfa360 100644 --- a/drivers/media/platform/Makefile +++ b/drivers/media/platform/Makefile @@ -92,3 +92,5 @@ obj-$(CONFIG_VIDEO_QCOM_CAMSS)+= qcom/camss-8x16/ obj-$(CONFIG_VIDEO_QCOM_VENUS) += qcom/venus/ obj-y += meson/ + +obj-$(CONFIG_VIDEO_SUN6I_CSI) += sunxi/sun6i-csi/ diff --git a/drivers/media/platform/sunxi/sun6i-csi/Kconfig b/drivers/media/platform/sunxi/sun6i-csi/Kconfig new file mode 100644 index ..018e3ec788c0 --- /dev/null +++ b/drivers/media/platform/sunxi/sun6i-csi/Kconfig @@ -0,0 +1,9 @@ +config VIDEO_SUN6I_CSI + tristate "Allwinner V3s Camera Sensor Interface driver" + depends on VIDEO_V4L2 && COMMON_CLK && VIDEO_V4L2_SUBDEV_API && HAS_DMA + depends on ARCH_SUNXI || COMPILE_TEST + select VIDEOBUF2_DMA_CONTIG + select REGMAP_MMIO + select V4L2_FWNODE + help + Support for the Allwinner Camera Sensor Interface Controller on V3s. diff --git a/drivers/media/platform/sunxi/sun6i-csi/Makefile b/drivers/media/platform/sunxi/sun6i-csi/Makefile new file mode 100644 index ..213cb6be9e9c --- /dev/null +++ b/drivers/media/platform/sunxi/sun6i-csi/Makefile @@ -0,0 +1,3 @@ +sun6i-csi-y += sun6i_video.o sun6i_csi.o + +obj-$(CONFIG_VIDEO_SUN6I_CSI) += sun6i-csi.o diff --git a/drivers/media/platform/sunxi/sun6i-csi/sun6i_csi.c b/drivers/media/platform/sunxi/sun6i-csi/sun6i_csi.c new file mode 100644 index ..d03a367dad44 --- /dev/null +++ b/drivers/media/platform/sunxi/sun6i-csi/sun6i_csi.c @@ -0,0 +1,932 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (c) 2011-2018 Magewell Electronics Co., Ltd. (Nanjing) + * All rights reserved. + * Author: Yong Deng + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "sun6i_csi.h" +#include "sun6i_csi_reg.h" + +#define MODULE_NAME"sun6i-csi" + +s
[PATCH v10 1/2] dt-bindings: media: Add Allwinner V3s Camera Sensor Interface (CSI)
Add binding documentation for Allwinner V3s CSI. Acked-by: Maxime Ripard Acked-by: Sakari Ailus Reviewed-by: Rob Herring Signed-off-by: Yong Deng --- .../devicetree/bindings/media/sun6i-csi.txt| 59 ++ 1 file changed, 59 insertions(+) create mode 100644 Documentation/devicetree/bindings/media/sun6i-csi.txt diff --git a/Documentation/devicetree/bindings/media/sun6i-csi.txt b/Documentation/devicetree/bindings/media/sun6i-csi.txt new file mode 100644 index ..2ff47a9507a6 --- /dev/null +++ b/Documentation/devicetree/bindings/media/sun6i-csi.txt @@ -0,0 +1,59 @@ +Allwinner V3s Camera Sensor Interface +- + +Allwinner V3s SoC features two CSI module. CSI0 is used for MIPI CSI-2 +interface and CSI1 is used for parallel interface. + +Required properties: + - compatible: value must be "allwinner,sun8i-v3s-csi" + - reg: base address and size of the memory-mapped region. + - interrupts: interrupt associated to this IP + - clocks: phandles to the clocks feeding the CSI +* bus: the CSI interface clock +* mod: the CSI module clock +* ram: the CSI DRAM clock + - clock-names: the clock names mentioned above + - resets: phandles to the reset line driving the CSI + +Each CSI node should contain one 'port' child node with one child 'endpoint' +node, according to the bindings defined in +Documentation/devicetree/bindings/media/video-interfaces.txt. As mentioned +above, the endpoint's bus type should be MIPI CSI-2 for CSI0 and parallel or +Bt656 for CSI1. + +Endpoint node properties for CSI1 +- + +- remote-endpoint : (required) a phandle to the bus receiver's endpoint + node +- bus-width: : (required) must be 8, 10, 12 or 16 +- pclk-sample : (optional) (default: sample on falling edge) +- hsync-active : (only required for parallel) +- vsync-active : (only required for parallel) + +Example: + +csi1: csi@1cb4000 { + compatible = "allwinner,sun8i-v3s-csi"; + reg = <0x01cb4000 0x1000>; + interrupts = ; + clocks = <&ccu CLK_BUS_CSI>, +<&ccu CLK_CSI1_SCLK>, +<&ccu CLK_DRAM_CSI>; + clock-names = "bus", "mod", "ram"; + resets = <&ccu RST_BUS_CSI>; + + port { + /* Parallel bus endpoint */ + csi1_ep: endpoint { + remote-endpoint = <&adv7611_ep>; + bus-width = <16>; + + /* If hsync-active/vsync-active are missing, + embedded BT.656 sync is used */ + hsync-active = <0>; /* Active low */ + vsync-active = <0>; /* Active low */ + pclk-sample = <1>; /* Rising */ + }; + }; +}; -- 1.8.3.1
[PATCH v10 0/2] Initial Allwinner V3s CSI Support
OK (Not Supported) Outputs: 0 Audio Outputs: 0 Modulators: 0 Input/Output configuration ioctls: test VIDIOC_ENUM/G/S/QUERY_STD: OK (Not Supported) test VIDIOC_ENUM/G/S/QUERY_DV_TIMINGS: OK (Not Supported) test VIDIOC_DV_TIMINGS_CAP: OK (Not Supported) test VIDIOC_G/S_EDID: OK (Not Supported) Test input 0: Control ioctls: test VIDIOC_QUERY_EXT_CTRL/QUERYMENU: OK (Not Supported) test VIDIOC_QUERYCTRL: OK (Not Supported) test VIDIOC_G/S_CTRL: OK (Not Supported) test VIDIOC_G/S/TRY_EXT_CTRLS: OK (Not Supported) test VIDIOC_(UN)SUBSCRIBE_EVENT/DQEVENT: OK (Not Supported) test VIDIOC_G/S_JPEGCOMP: OK (Not Supported) Standard Controls: 0 Private Controls: 0 Format ioctls: test VIDIOC_ENUM_FMT/FRAMESIZES/FRAMEINTERVALS: OK test VIDIOC_G/S_PARM: OK (Not Supported) test VIDIOC_G_FBUF: OK (Not Supported) test VIDIOC_G_FMT: OK test VIDIOC_TRY_FMT: OK test VIDIOC_S_FMT: OK test VIDIOC_G_SLICED_VBI_CAP: OK (Not Supported) test Cropping: OK (Not Supported) test Composing: OK (Not Supported) test Scaling: OK (Not Supported) Codec ioctls: test VIDIOC_(TRY_)ENCODER_CMD: OK (Not Supported) test VIDIOC_G_ENC_INDEX: OK (Not Supported) test VIDIOC_(TRY_)DECODER_CMD: OK (Not Supported) Buffer ioctls: test VIDIOC_REQBUFS/CREATE_BUFS/QUERYBUF: OK test VIDIOC_EXPBUF: OK Test input 0: Streaming ioctls: test read/write: OK (Not Supported) test MMAP: OK test USERPTR: OK (Not Supported) test DMABUF: Cannot test, specify --expbuf-device Stream using all formats: test MMAP for Format HM12, Frame Size 1280x720: Stride 1920, Field None: OK test MMAP for Format NV12, Frame Size 1280x720: Stride 1920, Field None: OK test MMAP for Format NV21, Frame Size 1280x720: Stride 1920, Field None: OK test MMAP for Format YU12, Frame Size 1280x720: Stride 1920, Field None: OK test MMAP for Format YV12, Frame Size 1280x720: Stride 1920, Field None: OK test MMAP for Format NV16, Frame Size 1280x720: Stride 2560, Field None: OK test MMAP for Format NV61, Frame Size 1280x720: Stride 2560, Field None: OK test MMAP for Format 422P, Frame Size 1280x720: Stride 2560, Field None: OK Total: 54, Succeeded: 54, Failed: 0, Warnings: 0 Yong Deng (2): dt-bindings: media: Add Allwinner V3s Camera Sensor Interface (CSI) media: V3s: Add support for Allwinner CSI. .../devicetree/bindings/media/sun6i-csi.txt| 59 ++ MAINTAINERS| 8 + drivers/media/platform/Kconfig | 1 + drivers/media/platform/Makefile| 2 + drivers/media/platform/sunxi/sun6i-csi/Kconfig | 9 + drivers/media/platform/sunxi/sun6i-csi/Makefile| 3 + drivers/media/platform/sunxi/sun6i-csi/sun6i_csi.c | 931 + drivers/media/platform/sunxi/sun6i-csi/sun6i_csi.h | 145 .../media/platform/sunxi/sun6i-csi/sun6i_csi_reg.h | 196 + .../media/platform/sunxi/sun6i-csi/sun6i_video.c | 767 + .../media/platform/sunxi/sun6i-csi/sun6i_video.h | 53 ++ 11 files changed, 2174 insertions(+) create mode 100644 Documentation/devicetree/bindings/media/sun6i-csi.txt create mode 100644 drivers/media/platform/sunxi/sun6i-csi/Kconfig create mode 100644 drivers/media/platform/sunxi/sun6i-csi/Makefile create mode 100644 drivers/media/platform/sunxi/sun6i-csi/sun6i_csi.c create mode 100644 drivers/media/platform/sunxi/sun6i-csi/sun6i_csi.h create mode 100644 drivers/media/platform/sunxi/sun6i-csi/sun6i_csi_reg.h create mode 100644 drivers/media/platform/sunxi/sun6i-csi/sun6i_video.c create mode 100644 drivers/media/platform/sunxi/sun6i-csi/sun6i_video.h -- 1.8.3.1
Re: [PATCH v9 0/2] Initial Allwinner V3s CSI Support
Hi Maxime, On Thu, 3 May 2018 19:14:10 +0200 Maxime Ripard wrote: > Hi Yong, > > On Tue, Mar 06, 2018 at 09:51:10AM +0800, Yong Deng wrote: > > This patchset add initial support for Allwinner V3s CSI. > > > > Allwinner V3s SoC features two CSI module. CSI0 is used for MIPI CSI-2 > > interface and CSI1 is used for parallel interface. This is not > > documented in datasheet but by test and guess. > > > > This patchset implement a v4l2 framework driver and add a binding > > documentation for it. > > > > Currently, the driver only support the parallel interface. And has been > > tested with a BT1120 signal which generating from FPGA. The following > > fetures are not support with this patchset: > > - ISP > > - MIPI-CSI2 > > - Master clock for camera sensor > > - Power regulator for the front end IC > > Do you plan on sending another version some time soon? It would be > awesome to have this in 4.18. I was waiting for Sakari Ailus's feedback. But ... I will send a new version soon. But not all suggestion from Sakari Ailus would be accepted. > > Thanks! > Maxime > > -- > Maxime Ripard, Bootlin (formerly Free Electrons) > Embedded Linux and Kernel engineering > https://bootlin.com Thanks, Yong
[PATCH] media: intel-ipu3: cio2: Handle IRQs until INT_STS is cleared
From: Bingbu Cao Interrupt behavior shows that some time the frame end and frame start of next frame is unstable and can range from several to hundreds of micro-sec. In the case of ~10us, isr may not clear next sof interrupt status in single handling, which prevents new interrupts from coming. Fix this by handling all pending IRQs before exiting isr, so any abnormal behavior results from very short interrupt status changes is protected. Signed-off-by: Bingbu Cao Signed-off-by: Andy Yeh Signed-off-by: Yong Zhi --- Hi, Sakari, Re-send with correct signed-off-by order. drivers/media/pci/intel/ipu3/ipu3-cio2.c | 32 ++-- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/drivers/media/pci/intel/ipu3/ipu3-cio2.c b/drivers/media/pci/intel/ipu3/ipu3-cio2.c index 7d768ec0f824..29027159eced 100644 --- a/drivers/media/pci/intel/ipu3/ipu3-cio2.c +++ b/drivers/media/pci/intel/ipu3/ipu3-cio2.c @@ -640,18 +640,10 @@ static const char *const cio2_port_errs[] = { "PKT2LONG", }; -static irqreturn_t cio2_irq(int irq, void *cio2_ptr) +static void cio2_irq_handle_once(struct cio2_device *cio2, u32 int_status) { - struct cio2_device *cio2 = cio2_ptr; void __iomem *const base = cio2->base; struct device *dev = &cio2->pci_dev->dev; - u32 int_status, int_clear; - - int_status = readl(base + CIO2_REG_INT_STS); - int_clear = int_status; - - if (!int_status) - return IRQ_NONE; if (int_status & CIO2_INT_IOOE) { /* @@ -770,9 +762,29 @@ static irqreturn_t cio2_irq(int irq, void *cio2_ptr) int_status &= ~(CIO2_INT_IOIE | CIO2_INT_IOIRQ); } - writel(int_clear, base + CIO2_REG_INT_STS); if (int_status) dev_warn(dev, "unknown interrupt 0x%x on INT\n", int_status); +} + +static irqreturn_t cio2_irq(int irq, void *cio2_ptr) +{ + struct cio2_device *cio2 = cio2_ptr; + void __iomem *const base = cio2->base; + struct device *dev = &cio2->pci_dev->dev; + u32 int_status; + + int_status = readl(base + CIO2_REG_INT_STS); + dev_dbg(dev, "isr enter - interrupt status 0x%x\n", int_status); + if (!int_status) + return IRQ_NONE; + + do { + writel(int_status, base + CIO2_REG_INT_STS); + cio2_irq_handle_once(cio2, int_status); + int_status = readl(base + CIO2_REG_INT_STS); + if (int_status) + dev_dbg(dev, "pending status 0x%x\n", int_status); + } while (int_status); return IRQ_HANDLED; } -- 2.7.4
RE: [PATCH v6 12/12] intel-ipu3: Add imgu top level pci device driver
Hi, Tomasz, Thanks for the review again. > -Original Message- > From: Tomasz Figa [mailto:tf...@chromium.org] > Sent: Thursday, April 26, 2018 12:15 AM > To: Zhi, Yong > Cc: Linux Media Mailing List ; Sakari Ailus > ; Mani, Rajmohan > ; Toivonen, Tuukka > ; Hu, Jerry W ; Zheng, > Jian Xu > Subject: Re: [PATCH v6 12/12] intel-ipu3: Add imgu top level pci device > driver > > Hi Yong, > > On Fri, Mar 30, 2018 at 11:15 AM Yong Zhi wrote: > [snip] > > +static int imgu_video_nodes_init(struct imgu_device *imgu) { > > + struct v4l2_pix_format_mplane *fmts[IPU3_CSS_QUEUES] = { NULL }; > > + struct v4l2_rect *rects[IPU3_CSS_RECTS] = { NULL }; > > + unsigned int i; > > + int r; > > + > > + imgu->buf_struct_size = sizeof(struct imgu_buffer); > > + > > + for (i = 0; i < IMGU_NODE_NUM; i++) { > > + imgu->nodes[i].name = imgu_node_map[i].name; > > + imgu->nodes[i].output = i < IMGU_QUEUE_FIRST_INPUT; > > + imgu->nodes[i].immutable = false; > > + imgu->nodes[i].enabled = false; > > + > > + if (i != IMGU_NODE_PARAMS && i != IMGU_NODE_STAT_3A) > > + fmts[imgu_node_map[i].css_queue] = > > + &imgu->nodes[i].vdev_fmt.fmt.pix_mp; > > + atomic_set(&imgu->nodes[i].sequence, 0); > > + } > > + > > + /* Master queue is always enabled */ > > + imgu->nodes[IMGU_QUEUE_MASTER].immutable = true; > > + imgu->nodes[IMGU_QUEUE_MASTER].enabled = true; > > + > > + r = ipu3_v4l2_register(imgu); > > + if (r) > > + return r; > > + > > + /* Set initial formats and initialize formats of video nodes */ > > + rects[IPU3_CSS_RECT_EFFECTIVE] = &imgu->rect.eff; > > + rects[IPU3_CSS_RECT_BDS] = &imgu->rect.bds; > > + ipu3_css_fmt_set(&imgu->css, fmts, rects); > > + > > + /* Pre-allocate dummy buffers */ > > + r = imgu_dummybufs_preallocate(imgu); > > + if (r) { > > + dev_err(&imgu->pci_dev->dev, > > + "failed to pre-allocate dummy buffers (%d)", r); > > + imgu_dummybufs_cleanup(imgu); > > No need to call ipu3_v4l2_unregister() here? > > (That's why I keep suggesting use of single return error path with labels > named after the first cleanup step that needs to be done, as it makes it > easier to spot such mistakes.) > Good catch, suggestion taken :) Maybe I should move the imgu_dummybufs_preallocate() out from imgu_video_nodes_init(). > > + return r; > > + } > > + > > + return 0; > > +} > > + > > +static void imgu_video_nodes_exit(struct imgu_device *imgu) { > > + imgu_dummybufs_cleanup(imgu); > > + ipu3_v4l2_unregister(imgu); > > +} > > Best regards, > Tomasz
RE: [PATCH v6 10/12] intel-ipu3: Add css pipeline programming
Hi, Tomasz, Thanks for the code review. > -Original Message- > From: Tomasz Figa [mailto:tf...@chromium.org] > Sent: Thursday, April 26, 2018 12:12 AM > To: Zhi, Yong > Cc: Linux Media Mailing List ; Sakari Ailus > ; Mani, Rajmohan > ; Toivonen, Tuukka > ; Hu, Jerry W ; Zheng, > Jian Xu > Subject: Re: [PATCH v6 10/12] intel-ipu3: Add css pipeline programming > > Hi Yong, > > On Fri, Mar 30, 2018 at 11:15 AM Yong Zhi wrote: > [snip] > > +int ipu3_css_init(struct device *dev, struct ipu3_css *css, > > + void __iomem *base, int length) { > > + int r, p, q, i; > > + > > + /* Initialize main data structure */ > > + css->dev = dev; > > + css->base = base; > > + css->iomem_length = length; > > + css->current_binary = IPU3_CSS_DEFAULT_BINARY; > > + css->pipe_id = IPU3_CSS_PIPE_ID_NUM; > > + css->vf_output_en = IPU3_NODE_VF_DISABLED; > > + spin_lock_init(&css->qlock); > > + > > + for (q = 0; q < IPU3_CSS_QUEUES; q++) { > > + r = ipu3_css_queue_init(&css->queue[q], NULL, 0); > > + if (r) > > + return r; > > + } > > + > > + r = ipu3_css_fw_init(css); > > + if (r) > > + return r; > > + > > + /* Allocate and map common structures with imgu hardware */ > > + > > + for (p = 0; p < IPU3_CSS_PIPE_ID_NUM; p++) > > + for (i = 0; i < IMGU_ABI_MAX_STAGES; i++) { > > + if (!ipu3_dmamap_alloc(dev, > > + > &css->xmem_sp_stage_ptrs[p][i], > > + sizeof(struct > imgu_abi_sp_stage))) > > checkpatch reports line over 80 characters here. Ack, I opted for alignment over line limit here , will fix in v7. > > > + goto error_no_memory; > > + if (!ipu3_dmamap_alloc(dev, > > + > &css->xmem_isp_stage_ptrs[p][i], > > + sizeof(struct > imgu_abi_isp_stage))) > > Ditto. Sure, thanks!! > > > + goto error_no_memory; > > + } > > Best regards, > Tomasz
[PATCH] media: intel-ipu3: cio2: Handle IRQs until INT_STS is cleared
From: Bingbu Cao Interrupt behavior shows that some time the frame end and frame start of next frame is unstable and can range from several to hundreds of micro-sec. In the case of ~10us, isr may not clear next sof interrupt status in single handling, which prevents new interrupts from coming. Fix this by handling all pending IRQs before exiting isr, so any abnormal behavior results from very short interrupt status changes is protected. Signed-off-by: Andy Yeh Signed-off-by: Bingbu Cao Signed-off-by: Yong Zhi --- drivers/media/pci/intel/ipu3/ipu3-cio2.c | 32 ++-- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/drivers/media/pci/intel/ipu3/ipu3-cio2.c b/drivers/media/pci/intel/ipu3/ipu3-cio2.c index 7d768ec..2902715 100644 --- a/drivers/media/pci/intel/ipu3/ipu3-cio2.c +++ b/drivers/media/pci/intel/ipu3/ipu3-cio2.c @@ -640,18 +640,10 @@ static const char *const cio2_port_errs[] = { "PKT2LONG", }; -static irqreturn_t cio2_irq(int irq, void *cio2_ptr) +static void cio2_irq_handle_once(struct cio2_device *cio2, u32 int_status) { - struct cio2_device *cio2 = cio2_ptr; void __iomem *const base = cio2->base; struct device *dev = &cio2->pci_dev->dev; - u32 int_status, int_clear; - - int_status = readl(base + CIO2_REG_INT_STS); - int_clear = int_status; - - if (!int_status) - return IRQ_NONE; if (int_status & CIO2_INT_IOOE) { /* @@ -770,9 +762,29 @@ static irqreturn_t cio2_irq(int irq, void *cio2_ptr) int_status &= ~(CIO2_INT_IOIE | CIO2_INT_IOIRQ); } - writel(int_clear, base + CIO2_REG_INT_STS); if (int_status) dev_warn(dev, "unknown interrupt 0x%x on INT\n", int_status); +} + +static irqreturn_t cio2_irq(int irq, void *cio2_ptr) +{ + struct cio2_device *cio2 = cio2_ptr; + void __iomem *const base = cio2->base; + struct device *dev = &cio2->pci_dev->dev; + u32 int_status; + + int_status = readl(base + CIO2_REG_INT_STS); + dev_dbg(dev, "isr enter - interrupt status 0x%x\n", int_status); + if (!int_status) + return IRQ_NONE; + + do { + writel(int_status, base + CIO2_REG_INT_STS); + cio2_irq_handle_once(cio2, int_status); + int_status = readl(base + CIO2_REG_INT_STS); + if (int_status) + dev_dbg(dev, "pending status 0x%x\n", int_status); + } while (int_status); return IRQ_HANDLED; } -- 2.7.4
[RFC PATCH]: intel-ipu3: Add uAPI documentation
This is a preliminary effort to add documentation for the following BNR(bayer noise reduction) structs: ipu3_uapi_bnr_static_config_wb_gains_config ipu3_uapi_bnr_static_config_wb_gains_thr_config ipu3_uapi_bnr_static_config_thr_coeffs_config ipu3_uapi_bnr_static_config_thr_ctrl_shd_config ipu3_uapi_bnr_static_config_opt_center_sqr_config ipu3_uapi_bnr_static_config_bp_ctrl_config ipu3_uapi_bnr_static_config_dn_detect_ctrl_config ipu3_uapi_bnr_static_config_opt_center_sqr_config ipu3_uapi_bnr_static_config_green_disparity The feedback on this patch will be used towards the documentation of reset of the uAPI in intel-ipu3.h. Link to v6 IPU3 ImgU patchset: https://patchwork.kernel.org/patch/10316725/> Signed-off-by: Yong Zhi Signed-off-by: Chao C Li --- Documentation/media/media_uapi.rst |1 + Documentation/media/uapi/intel-ipu3.rst |8 + include/uapi/linux/intel-ipu3.h | 1520 +++ 3 files changed, 1529 insertions(+) create mode 100644 Documentation/media/uapi/intel-ipu3.rst create mode 100644 include/uapi/linux/intel-ipu3.h diff --git a/Documentation/media/media_uapi.rst b/Documentation/media/media_uapi.rst index 28eb35a1f965..edfa674b49c3 100644 --- a/Documentation/media/media_uapi.rst +++ b/Documentation/media/media_uapi.rst @@ -31,3 +31,4 @@ License". uapi/cec/cec-api uapi/gen-errors uapi/fdl-appendix +uapi/intel-ipu3 diff --git a/Documentation/media/uapi/intel-ipu3.rst b/Documentation/media/uapi/intel-ipu3.rst new file mode 100644 index ..d4d9b2806fe9 --- /dev/null +++ b/Documentation/media/uapi/intel-ipu3.rst @@ -0,0 +1,8 @@ +.. -*- coding: utf-8; mode: rst -*- + +.. _intel-ipu3: + +Intel IPU3 ImgU uAPI headers + + +.. kernel-doc:: include/uapi/linux/intel-ipu3.h diff --git a/include/uapi/linux/intel-ipu3.h b/include/uapi/linux/intel-ipu3.h new file mode 100644 index ..34b071524beb --- /dev/null +++ b/include/uapi/linux/intel-ipu3.h @@ -0,0 +1,1520 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* Copyright (C) 2018 Intel Corporation */ + +#ifndef __IPU3_UAPI_H +#define __IPU3_UAPI_H + +#include + +#define IPU3_UAPI_ISP_VEC_ELEMS64 + +#define IMGU_ABI_PAD __aligned(IPU3_UAPI_ISP_WORD_BYTES) +#define IPU3_ALIGN __attribute__((aligned(IPU3_UAPI_ISP_WORD_BYTES))) + +#define IPU3_UAPI_ISP_WORD_BYTES 32 +#define IPU3_UAPI_MAX_STRIPES 2 + +/*** ipu3_uapi_stats_3a ***/ + +#define IPU3_UAPI_MAX_BUBBLE_SIZE 10 + +#define IPU3_UAPI_AE_COLORS4 +#define IPU3_UAPI_AE_BINS 256 + +#define IPU3_UAPI_AWB_MD_ITEM_SIZE 8 +#define IPU3_UAPI_AWB_MAX_SETS 60 +#define IPU3_UAPI_AWB_SET_SIZE 0x500 +#define IPU3_UAPI_AWB_SPARE_FOR_BUBBLES \ + (IPU3_UAPI_MAX_BUBBLE_SIZE * IPU3_UAPI_MAX_STRIPES * \ +IPU3_UAPI_AWB_MD_ITEM_SIZE) +#define IPU3_UAPI_AWB_MAX_BUFFER_SIZE \ + (IPU3_UAPI_AWB_MAX_SETS * \ +(IPU3_UAPI_AWB_SET_SIZE + IPU3_UAPI_AWB_SPARE_FOR_BUBBLES)) + +#define IPU3_UAPI_AF_MAX_SETS 24 +#define IPU3_UAPI_AF_MD_ITEM_SIZE 4 +#define IPU3_UAPI_AF_SPARE_FOR_BUBBLES \ + (IPU3_UAPI_MAX_BUBBLE_SIZE * IPU3_UAPI_MAX_STRIPES * \ +IPU3_UAPI_AF_MD_ITEM_SIZE) +#define IPU3_UAPI_AF_Y_TABLE_SET_SIZE 0x80 +#define IPU3_UAPI_AF_Y_TABLE_MAX_SIZE \ + (IPU3_UAPI_AF_MAX_SETS * \ +(IPU3_UAPI_AF_Y_TABLE_SET_SIZE + IPU3_UAPI_AF_SPARE_FOR_BUBBLES) * \ +IPU3_UAPI_MAX_STRIPES) + +#define IPU3_UAPI_AWB_FR_MAX_SETS 24 +#define IPU3_UAPI_AWB_FR_MD_ITEM_SIZE 8 +#define IPU3_UAPI_AWB_FR_BAYER_TBL_SIZE0x100 +#define IPU3_UAPI_AWB_FR_SPARE_FOR_BUBBLES \ + (IPU3_UAPI_MAX_BUBBLE_SIZE * IPU3_UAPI_MAX_STRIPES * \ +IPU3_UAPI_AWB_FR_MD_ITEM_SIZE) +#define IPU3_UAPI_AWB_FR_BAYER_TABLE_MAX_SIZE \ + (IPU3_UAPI_AWB_FR_MAX_SETS * \ + (IPU3_UAPI_AWB_FR_BAYER_TBL_SIZE + \ +IPU3_UAPI_AWB_FR_SPARE_FOR_BUBBLES) * IPU3_UAPI_MAX_STRIPES) + +struct ipu3_uapi_grid_config { + __u8 width; /* 6 or 7 (rgbs_grd_cfg) bits */ + __u8 height; + __u16 block_width_log2:3; + __u16 block_height_log2:3; + __u16 height_per_slice:8; /* default value 1 */ + __u16 x_start; /* 12 bits */ + __u16 y_start; +#define IPU3_UAPI_GRID_START_MASK ((1 << 12) - 1) +#define IPU3_UAPI_GRID_Y_START_EN (1 << 15) + __u16 x_end;/* 12 bits */ + __u16 y_end; +} __packed; + +struct ipu3_uapi_awb_meta_data { + __u8 meta_data_buffer[IPU3_UAPI_AWB_MAX_BUFFER_SIZE]; +} __packed; + +struct ipu3
[PATCH v6 11/12] intel-ipu3: Add v4l2 driver based on media framework
Implement video driver that utilizes v4l2, vb2 queue support and media controller APIs. The driver exposes single subdevice and six nodes. Signed-off-by: Yong Zhi Signed-off-by: Ramya Vijaykumar --- drivers/media/pci/intel/ipu3/ipu3-v4l2.c | 1089 ++ 1 file changed, 1089 insertions(+) create mode 100644 drivers/media/pci/intel/ipu3/ipu3-v4l2.c diff --git a/drivers/media/pci/intel/ipu3/ipu3-v4l2.c b/drivers/media/pci/intel/ipu3/ipu3-v4l2.c new file mode 100644 index ..1095ef8a29a5 --- /dev/null +++ b/drivers/media/pci/intel/ipu3/ipu3-v4l2.c @@ -0,0 +1,1089 @@ +// SPDX-License-Identifier: GPL-2.0 +// Copyright (C) 2018 Intel Corporation + +#include +#include + +#include + +#include "ipu3.h" +#include "ipu3-dmamap.h" + +/ v4l2_subdev_ops / + +static int ipu3_subdev_open(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh) +{ + struct imgu_device *imgu = container_of(sd, struct imgu_device, subdev); + struct v4l2_rect try_crop = { + .top = 0, + .left = 0, + .height = imgu->nodes[IMGU_NODE_IN].vdev_fmt.fmt.pix_mp.height, + .width = imgu->nodes[IMGU_NODE_IN].vdev_fmt.fmt.pix_mp.width, + }; + unsigned int i; + + /* Initialize try_fmt */ + for (i = 0; i < IMGU_NODE_NUM; i++) + *v4l2_subdev_get_try_format(sd, fh->pad, i) = + imgu->nodes[i].pad_fmt; + + *v4l2_subdev_get_try_crop(sd, fh->pad, IMGU_NODE_IN) = try_crop; + + return 0; +} + +static int ipu3_subdev_s_stream(struct v4l2_subdev *sd, int enable) +{ + struct imgu_device *imgu = container_of(sd, struct imgu_device, subdev); + int r = 0; + + r = imgu_s_stream(imgu, enable); + if (!r) + imgu->streaming = enable; + + return r; +} + +static int ipu3_subdev_get_fmt(struct v4l2_subdev *sd, + struct v4l2_subdev_pad_config *cfg, + struct v4l2_subdev_format *fmt) +{ + struct imgu_device *imgu = container_of(sd, struct imgu_device, subdev); + struct v4l2_mbus_framefmt *mf; + u32 pad = fmt->pad; + + if (fmt->which == V4L2_SUBDEV_FORMAT_ACTIVE) { + fmt->format = imgu->nodes[pad].pad_fmt; + } else { + mf = v4l2_subdev_get_try_format(sd, cfg, pad); + fmt->format = *mf; + } + + return 0; +} + +static int ipu3_subdev_set_fmt(struct v4l2_subdev *sd, + struct v4l2_subdev_pad_config *cfg, + struct v4l2_subdev_format *fmt) +{ + struct imgu_device *imgu = container_of(sd, struct imgu_device, subdev); + struct v4l2_mbus_framefmt *mf; + u32 pad = fmt->pad; + + if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) + mf = v4l2_subdev_get_try_format(sd, cfg, pad); + else + mf = &imgu->nodes[pad].pad_fmt; + + fmt->format.code = mf->code; + /* Clamp the w and h based on the hardware capabilities */ + if (imgu->subdev_pads[pad].flags & MEDIA_PAD_FL_SOURCE) { + fmt->format.width = clamp(fmt->format.width, + IPU3_OUTPUT_MIN_WIDTH, + IPU3_OUTPUT_MAX_WIDTH); + fmt->format.height = clamp(fmt->format.height, + IPU3_OUTPUT_MIN_HEIGHT, + IPU3_OUTPUT_MAX_HEIGHT); + } else { + fmt->format.width = clamp(fmt->format.width, + IPU3_INPUT_MIN_WIDTH, + IPU3_INPUT_MAX_WIDTH); + fmt->format.height = clamp(fmt->format.height, + IPU3_INPUT_MIN_HEIGHT, + IPU3_INPUT_MAX_HEIGHT); + } + + *mf = fmt->format; + + return 0; +} + +static int ipu3_subdev_get_selection(struct v4l2_subdev *sd, +struct v4l2_subdev_pad_config *cfg, +struct v4l2_subdev_selection *sel) +{ + struct imgu_device *imgu = container_of(sd, struct imgu_device, subdev); + struct v4l2_rect *try_sel, *r; + + if (sel->pad != IMGU_NODE_IN) + return -EINVAL; + + switch (sel->target) { + case V4L2_SEL_TGT_CROP: + try_sel = v4l2_subdev_get_try_crop(sd, cfg, sel->pad); + r = &imgu->rect.eff; + break; + case V4L2_SEL_TGT_COMPOSE: + try_sel = v4l2_subdev_get_try_compose(sd, cfg, sel->pad); + r = &imgu->rect.bds; + break; + default: + return -EINVAL; + } + + if
[PATCH v6 05/12] intel-ipu3: css: Add dma buff pool utility functions
The pools are used to store previous parameters set by user with the parameter queue. Due to pipelining, there needs to be multiple sets (up to four) of parameters which are queued in a host-to-sp queue. Signed-off-by: Yong Zhi --- drivers/media/pci/intel/ipu3/ipu3-css-pool.c | 131 +++ 1 file changed, 131 insertions(+) create mode 100644 drivers/media/pci/intel/ipu3/ipu3-css-pool.c diff --git a/drivers/media/pci/intel/ipu3/ipu3-css-pool.c b/drivers/media/pci/intel/ipu3/ipu3-css-pool.c new file mode 100644 index ..84f6a7801a01 --- /dev/null +++ b/drivers/media/pci/intel/ipu3/ipu3-css-pool.c @@ -0,0 +1,131 @@ +// SPDX-License-Identifier: GPL-2.0 +// Copyright (C) 2018 Intel Corporation + +#include + +#include "ipu3-css-pool.h" +#include "ipu3-dmamap.h" + +int ipu3_css_dma_buffer_resize(struct device *dev, struct ipu3_css_map *map, + size_t size) +{ + if (map->size < size && map->vaddr) { + dev_warn(dev, "dma buffer is resized from %zu to %zu", +map->size, size); + + ipu3_dmamap_free(dev, map); + if (!ipu3_dmamap_alloc(dev, map, size)) + return -ENOMEM; + } + + return 0; +} + +void ipu3_css_pool_cleanup(struct device *dev, struct ipu3_css_pool *pool) +{ + unsigned int i; + + for (i = 0; i < IPU3_CSS_POOL_SIZE; i++) + ipu3_dmamap_free(dev, &pool->entry[i].param); +} + +int ipu3_css_pool_init(struct device *dev, struct ipu3_css_pool *pool, + size_t size) +{ + unsigned int i; + + for (i = 0; i < IPU3_CSS_POOL_SIZE; i++) { + /* +* entry[i].framenum is initialized to INT_MIN so that +* ipu3_css_pool_check() can treat it as usesable slot. +*/ + pool->entry[i].framenum = INT_MIN; + + if (size == 0) { + pool->entry[i].param.vaddr = NULL; + continue; + } + + if (!ipu3_dmamap_alloc(dev, &pool->entry[i].param, size)) + goto fail; + } + + pool->last = IPU3_CSS_POOL_SIZE; + + return 0; + +fail: + ipu3_css_pool_cleanup(dev, pool); + return -ENOMEM; +} + +/* + * Check that the following call to pool_get succeeds. + * Return negative on error. + */ +static int ipu3_css_pool_check(struct ipu3_css_pool *pool, long framenum) +{ + /* Get the oldest entry */ + int n = (pool->last + 1) % IPU3_CSS_POOL_SIZE; + long diff = framenum - pool->entry[n].framenum; + + /* if framenum wraps around and becomes smaller than entry n */ + if (diff < 0) + diff += LONG_MAX; + + /* +* pool->entry[n].framenum stores the frame number where that +* entry was allocated. If that was allocated more than POOL_SIZE +* frames back, it is old enough that we know it is no more in +* use by firmware. +*/ + if (diff > IPU3_CSS_POOL_SIZE) + return n; + + return -ENOSPC; +} + +/* + * Allocate a new parameter from pool at frame number `framenum'. + * Release the oldest entry in the pool to make space for the new entry. + * Return negative on error. + */ +int ipu3_css_pool_get(struct ipu3_css_pool *pool, long framenum) +{ + int n = ipu3_css_pool_check(pool, framenum); + + if (n < 0) + return n; + + pool->entry[n].framenum = framenum; + pool->last = n; + + return n; +} + +/* + * Undo, for all practical purposes, the effect of pool_get(). + */ +void ipu3_css_pool_put(struct ipu3_css_pool *pool) +{ + pool->entry[pool->last].framenum = INT_MIN; + pool->last = (pool->last + IPU3_CSS_POOL_SIZE - 1) % IPU3_CSS_POOL_SIZE; +} + +/* + * Return the nth entry from last, if that entry has no frame stored, + * return a null map instead to indicate frame not available for the entry. + */ +const struct ipu3_css_map * +ipu3_css_pool_last(struct ipu3_css_pool *pool, unsigned int n) +{ + static const struct ipu3_css_map null_map = { 0 }; + int i = (pool->last + IPU3_CSS_POOL_SIZE - n) % IPU3_CSS_POOL_SIZE; + + WARN_ON(n >= IPU3_CSS_POOL_SIZE); + + if (pool->entry[i].framenum < 0) + return &null_map; + + return &pool->entry[i].param; +} -- 2.7.4
[PATCH v6 02/12] intel-ipu3: Add user space API definitions
Define the structures and macros to be used by public. Signed-off-by: Yong Zhi Signed-off-by: Rajmohan Mani --- include/uapi/linux/intel-ipu3.h | 1403 +++ 1 file changed, 1403 insertions(+) create mode 100644 include/uapi/linux/intel-ipu3.h diff --git a/include/uapi/linux/intel-ipu3.h b/include/uapi/linux/intel-ipu3.h new file mode 100644 index ..694ef0c8d7a7 --- /dev/null +++ b/include/uapi/linux/intel-ipu3.h @@ -0,0 +1,1403 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* Copyright (C) 2018 Intel Corporation */ + +#ifndef __IPU3_UAPI_H +#define __IPU3_UAPI_H + +#include + +#define IPU3_UAPI_ISP_VEC_ELEMS64 + +#define IMGU_ABI_PAD __aligned(IPU3_UAPI_ISP_WORD_BYTES) +#define IPU3_ALIGN __attribute__((aligned(IPU3_UAPI_ISP_WORD_BYTES))) + +#define IPU3_UAPI_ISP_WORD_BYTES 32 +#define IPU3_UAPI_MAX_STRIPES 2 + +/*** ipu3_uapi_stats_3a ***/ + +#define IPU3_UAPI_MAX_BUBBLE_SIZE 10 + +#define IPU3_UAPI_AE_COLORS4 +#define IPU3_UAPI_AE_BINS 256 + +#define IPU3_UAPI_AWB_MD_ITEM_SIZE 8 +#define IPU3_UAPI_AWB_MAX_SETS 60 +#define IPU3_UAPI_AWB_SET_SIZE 0x500 +#define IPU3_UAPI_AWB_SPARE_FOR_BUBBLES \ + (IPU3_UAPI_MAX_BUBBLE_SIZE * IPU3_UAPI_MAX_STRIPES * \ +IPU3_UAPI_AWB_MD_ITEM_SIZE) +#define IPU3_UAPI_AWB_MAX_BUFFER_SIZE \ + (IPU3_UAPI_AWB_MAX_SETS * \ +(IPU3_UAPI_AWB_SET_SIZE + IPU3_UAPI_AWB_SPARE_FOR_BUBBLES)) + +#define IPU3_UAPI_AF_MAX_SETS 24 +#define IPU3_UAPI_AF_MD_ITEM_SIZE 4 +#define IPU3_UAPI_AF_SPARE_FOR_BUBBLES \ + (IPU3_UAPI_MAX_BUBBLE_SIZE * IPU3_UAPI_MAX_STRIPES * \ +IPU3_UAPI_AF_MD_ITEM_SIZE) +#define IPU3_UAPI_AF_Y_TABLE_SET_SIZE 0x80 +#define IPU3_UAPI_AF_Y_TABLE_MAX_SIZE \ + (IPU3_UAPI_AF_MAX_SETS * \ +(IPU3_UAPI_AF_Y_TABLE_SET_SIZE + IPU3_UAPI_AF_SPARE_FOR_BUBBLES) * \ +IPU3_UAPI_MAX_STRIPES) + +#define IPU3_UAPI_AWB_FR_MAX_SETS 24 +#define IPU3_UAPI_AWB_FR_MD_ITEM_SIZE 8 +#define IPU3_UAPI_AWB_FR_BAYER_TBL_SIZE0x100 +#define IPU3_UAPI_AWB_FR_SPARE_FOR_BUBBLES \ + (IPU3_UAPI_MAX_BUBBLE_SIZE * IPU3_UAPI_MAX_STRIPES * \ +IPU3_UAPI_AWB_FR_MD_ITEM_SIZE) +#define IPU3_UAPI_AWB_FR_BAYER_TABLE_MAX_SIZE \ + (IPU3_UAPI_AWB_FR_MAX_SETS * \ + (IPU3_UAPI_AWB_FR_BAYER_TBL_SIZE + \ +IPU3_UAPI_AWB_FR_SPARE_FOR_BUBBLES) * IPU3_UAPI_MAX_STRIPES) + +struct ipu3_uapi_grid_config { + __u8 width; /* 6 or 7 (rgbs_grd_cfg) bits */ + __u8 height; + __u16 block_width_log2:3; + __u16 block_height_log2:3; + __u16 height_per_slice:8; /* default value 1 */ + __u16 x_start; /* 12 bits */ + __u16 y_start; +#define IPU3_UAPI_GRID_START_MASK ((1 << 12) - 1) +#define IPU3_UAPI_GRID_Y_START_EN (1 << 15) + __u16 x_end;/* 12 bits */ + __u16 y_end; +} __packed; + +struct ipu3_uapi_awb_meta_data { + __u8 meta_data_buffer[IPU3_UAPI_AWB_MAX_BUFFER_SIZE]; +} __packed; + +struct ipu3_uapi_awb_raw_buffer { + struct ipu3_uapi_awb_meta_data meta_data; +} __packed; + +struct IPU3_ALIGN ipu3_uapi_awb_config_s { + __u16 rgbs_thr_gr; + __u16 rgbs_thr_r; + __u16 rgbs_thr_gb; + __u16 rgbs_thr_b; +/* controls generation of meta_data (like FF enable/disable) */ +#define IPU3_UAPI_AWB_RGBS_THR_B_EN(1 << 14) +#define IPU3_UAPI_AWB_RGBS_THR_B_INCL_SAT (1 << 15) + + struct ipu3_uapi_grid_config grid; +} __packed; + +struct ipu3_uapi_ae_raw_buffer { + __u32 vals[IPU3_UAPI_AE_BINS * IPU3_UAPI_AE_COLORS]; +} __packed; + +struct ipu3_uapi_ae_raw_buffer_aligned { + struct ipu3_uapi_ae_raw_buffer buff IPU3_ALIGN; +} __packed; + +struct ipu3_uapi_ae_grid_config { + __u8 width; + __u8 height; + __u8 block_width_log2:4; + __u8 block_height_log2:4; + __u8 __reserved0:5; + __u8 ae_en:1; + __u8 rst_hist_array:1; + __u8 done_rst_hist_array:1; + __u16 x_start; /* 12 bits */ + __u16 y_start; + __u16 x_end; + __u16 y_end; +} __packed; + +struct ipu3_uapi_af_filter_config { + struct { + __u8 a1; + __u8 a2; + __u8 a3; + __u8 a4; + } y1_coeff_0; + struct { + __u8 a5; + __u8 a6; + __u8 a7; + __u8 a8; + } y1_coeff_1; + struct { + __u8 a9; + __u8 a10; + __u8 a11; + __u8 a12; + } y1_
[PATCH v6 04/12] intel-ipu3: Implement DMA mapping functions
From: Tomasz Figa This driver uses IOVA space for buffer mapping through IPU3 MMU to transfer data between imaging pipelines and system DDR. Signed-off-by: Tomasz Figa Signed-off-by: Yong Zhi --- drivers/media/pci/intel/ipu3/ipu3-css-pool.h | 36 drivers/media/pci/intel/ipu3/ipu3-dmamap.c | 280 +++ drivers/media/pci/intel/ipu3/ipu3-dmamap.h | 22 +++ drivers/media/pci/intel/ipu3/ipu3.h | 151 +++ 4 files changed, 489 insertions(+) create mode 100644 drivers/media/pci/intel/ipu3/ipu3-css-pool.h create mode 100644 drivers/media/pci/intel/ipu3/ipu3-dmamap.c create mode 100644 drivers/media/pci/intel/ipu3/ipu3-dmamap.h create mode 100644 drivers/media/pci/intel/ipu3/ipu3.h diff --git a/drivers/media/pci/intel/ipu3/ipu3-css-pool.h b/drivers/media/pci/intel/ipu3/ipu3-css-pool.h new file mode 100644 index ..4b22e0856232 --- /dev/null +++ b/drivers/media/pci/intel/ipu3/ipu3-css-pool.h @@ -0,0 +1,36 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* Copyright (C) 2018 Intel Corporation */ + +#ifndef __IPU3_UTIL_H +#define __IPU3_UTIL_H + +struct device; + +#define IPU3_CSS_POOL_SIZE 4 + +struct ipu3_css_map { + size_t size; + void *vaddr; + dma_addr_t daddr; + struct vm_struct *vma; +}; + +struct ipu3_css_pool { + struct { + struct ipu3_css_map param; + long framenum; + } entry[IPU3_CSS_POOL_SIZE]; + unsigned int last; /* Latest entry */ +}; + +int ipu3_css_dma_buffer_resize(struct device *dev, struct ipu3_css_map *map, + size_t size); +void ipu3_css_pool_cleanup(struct device *dev, struct ipu3_css_pool *pool); +int ipu3_css_pool_init(struct device *dev, struct ipu3_css_pool *pool, + size_t size); +int ipu3_css_pool_get(struct ipu3_css_pool *pool, long framenum); +void ipu3_css_pool_put(struct ipu3_css_pool *pool); +const struct ipu3_css_map *ipu3_css_pool_last(struct ipu3_css_pool *pool, + unsigned int last); + +#endif diff --git a/drivers/media/pci/intel/ipu3/ipu3-dmamap.c b/drivers/media/pci/intel/ipu3/ipu3-dmamap.c new file mode 100644 index ..b2bc5d00debc --- /dev/null +++ b/drivers/media/pci/intel/ipu3/ipu3-dmamap.c @@ -0,0 +1,280 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (C) 2018 Intel Corporation + * Copyright (C) 2018 Google, Inc. + * + * Author: Tomasz Figa + * Author: Yong Zhi + */ + +#include + +#include "ipu3.h" +#include "ipu3-css-pool.h" +#include "ipu3-mmu.h" + +/* + * Free a buffer allocated by ipu3_dmamap_alloc_buffer() + */ +static void ipu3_dmamap_free_buffer(struct page **pages, + size_t size) +{ + int count = size >> PAGE_SHIFT; + + while (count--) + __free_page(pages[count]); + kvfree(pages); +} + +/* + * Based on the implementation of __iommu_dma_alloc_pages() + * defined in drivers/iommu/dma-iommu.c + */ +static struct page **ipu3_dmamap_alloc_buffer(size_t size, + unsigned long order_mask, + gfp_t gfp) +{ + struct page **pages; + unsigned int i = 0, count = size >> PAGE_SHIFT; + const gfp_t high_order_gfp = __GFP_NOWARN | __GFP_NORETRY; + + /* Allocate mem for array of page ptrs */ + pages = kvmalloc_array(count, sizeof(struct page *), GFP_KERNEL); + + if (!pages) + return NULL; + + order_mask &= (2U << MAX_ORDER) - 1; + if (!order_mask) + return NULL; + + gfp |= __GFP_HIGHMEM | __GFP_ZERO; + + while (count) { + struct page *page = NULL; + unsigned int order_size; + + for (order_mask &= (2U << __fls(count)) - 1; +order_mask; order_mask &= ~order_size) { + unsigned int order = __fls(order_mask); + + order_size = 1U << order; + page = alloc_pages((order_mask - order_size) ? + gfp | high_order_gfp : gfp, order); + if (!page) + continue; + if (!order) + break; + if (!PageCompound(page)) { + split_page(page, order); + break; + } + + __free_pages(page, order); + } + if (!page) { + ipu3_dmamap_free_buffer(pages, i << PAGE_SHIFT); + return NULL; + } + count -= order_size; + while (order_size--) + pages[i++] = page++; + } + + return pages; +} + +/** + * ipu3_dma
[PATCH v6 01/12] v4l: Add Intel IPU3 meta buffer formats
Add IPU3-specific meta formats for parameter processing and 3A statistics: V4L2_META_FMT_IPU3_PARAMS V4L2_META_FMT_IPU3_STAT_3A Signed-off-by: Yong Zhi --- drivers/media/v4l2-core/v4l2-ioctl.c | 2 ++ include/uapi/linux/videodev2.h | 4 2 files changed, 6 insertions(+) diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c index ec98b93b2a55..5360b3915af7 100644 --- a/drivers/media/v4l2-core/v4l2-ioctl.c +++ b/drivers/media/v4l2-core/v4l2-ioctl.c @@ -1257,6 +1257,8 @@ static void v4l_fill_fmtdesc(struct v4l2_fmtdesc *fmt) case V4L2_META_FMT_VSP1_HGO:descr = "R-Car VSP1 1-D Histogram"; break; case V4L2_META_FMT_VSP1_HGT:descr = "R-Car VSP1 2-D Histogram"; break; case V4L2_META_FMT_UVC: descr = "UVC payload header metadata"; break; + case V4L2_META_FMT_IPU3_PARAMS: descr = "IPU3 processing parameters"; break; + case V4L2_META_FMT_IPU3_STAT_3A:descr = "IPU3 3A statistics"; break; default: /* Compressed formats */ diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h index e20d10df75c1..83ef5a0fbdc2 100644 --- a/include/uapi/linux/videodev2.h +++ b/include/uapi/linux/videodev2.h @@ -698,6 +698,10 @@ struct v4l2_pix_format { #define V4L2_META_FMT_VSP1_HGTv4l2_fourcc('V', 'S', 'P', 'T') /* R-Car VSP1 2-D Histogram */ #define V4L2_META_FMT_UVC v4l2_fourcc('U', 'V', 'C', 'H') /* UVC Payload Header metadata */ +/* Vendor specific - used for IPU3 camera sub-system */ +#define V4L2_META_FMT_IPU3_PARAMS v4l2_fourcc('i', 'p', '3', 'p') /* IPU3 params */ +#define V4L2_META_FMT_IPU3_STAT_3A v4l2_fourcc('i', 'p', '3', 's') /* IPU3 3A statistics */ + /* priv field value to indicates that subsequent fields are valid. */ #define V4L2_PIX_FMT_PRIV_MAGIC0xfeedcafe -- 2.7.4
[PATCH v6 03/12] intel-ipu3: mmu: Implement driver
From: Tomasz Figa This driver translates IO virtual address to physical address based on two levels page tables. Signed-off-by: Tomasz Figa Signed-off-by: Yong Zhi --- drivers/media/pci/intel/ipu3/ipu3-mmu.c | 560 drivers/media/pci/intel/ipu3/ipu3-mmu.h | 28 ++ 2 files changed, 588 insertions(+) create mode 100644 drivers/media/pci/intel/ipu3/ipu3-mmu.c create mode 100644 drivers/media/pci/intel/ipu3/ipu3-mmu.h diff --git a/drivers/media/pci/intel/ipu3/ipu3-mmu.c b/drivers/media/pci/intel/ipu3/ipu3-mmu.c new file mode 100644 index ..a4b3e1680bbb --- /dev/null +++ b/drivers/media/pci/intel/ipu3/ipu3-mmu.c @@ -0,0 +1,560 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (c) 2018 Intel Corporation. + * Copyright (C) 2018 Google, Inc. + * + * Author: Tuukka Toivonen + * Author: Sakari Ailus + * Author: Samu Onkalo + * Author: Tomasz Figa + * + */ + +#include +#include +#include +#include +#include + +#include + +#include "ipu3-mmu.h" + +#define IPU3_PAGE_SHIFT12 +#define IPU3_PAGE_SIZE (1UL << IPU3_PAGE_SHIFT) + +#define IPU3_PT_BITS 10 +#define IPU3_PT_PTES (1UL << IPU3_PT_BITS) +#define IPU3_PT_SIZE (IPU3_PT_PTES << 2) +#define IPU3_PT_ORDER (IPU3_PT_SIZE >> PAGE_SHIFT) + +#define IPU3_ADDR2PTE(addr)((addr) >> IPU3_PAGE_SHIFT) +#define IPU3_PTE2ADDR(pte) ((phys_addr_t)(pte) << IPU3_PAGE_SHIFT) + +#define IPU3_L2PT_SHIFTIPU3_PT_BITS +#define IPU3_L2PT_MASK ((1UL << IPU3_L2PT_SHIFT) - 1) + +#define IPU3_L1PT_SHIFTIPU3_PT_BITS +#define IPU3_L1PT_MASK ((1UL << IPU3_L1PT_SHIFT) - 1) + +#define IPU3_MMU_ADDRESS_BITS (IPU3_PAGE_SHIFT + \ +IPU3_L2PT_SHIFT + \ +IPU3_L1PT_SHIFT) + +#define IMGU_REG_BASE 0x4000 +#define REG_TLB_INVALIDATE (IMGU_REG_BASE + 0x300) +#define TLB_INVALIDATE 1 +#define REG_L1_PHYS(IMGU_REG_BASE + 0x304) /* 27-bit pfn */ +#define REG_GP_HALT(IMGU_REG_BASE + 0x5dc) +#define REG_GP_HALTED (IMGU_REG_BASE + 0x5e0) + +struct ipu3_mmu { + struct device *dev; + void __iomem *base; + /* protect access to l2pts, l1pt */ + spinlock_t lock; + + void *dummy_page; + u32 dummy_page_pteval; + + u32 *dummy_l2pt; + u32 dummy_l2pt_pteval; + + u32 **l2pts; + u32 *l1pt; + + struct ipu3_mmu_info geometry; +}; + +static inline struct ipu3_mmu *to_ipu3_mmu(struct ipu3_mmu_info *info) +{ + return container_of(info, struct ipu3_mmu, geometry); +} + +/** + * ipu3_mmu_tlb_invalidate - invalidate translation look-aside buffer + * @mmu: MMU to perform the invalidate operation on + * + * This function invalidates the whole TLB. Must be called when the hardware + * is powered on. + */ +static void ipu3_mmu_tlb_invalidate(struct ipu3_mmu *mmu) +{ + writel(TLB_INVALIDATE, mmu->base + REG_TLB_INVALIDATE); +} + +static void call_if_ipu3_is_powered(struct ipu3_mmu *mmu, + void (*func)(struct ipu3_mmu *mmu)) +{ + pm_runtime_get_noresume(mmu->dev); + if (pm_runtime_active(mmu->dev)) + func(mmu); + pm_runtime_put(mmu->dev); +} + +/** + * ipu3_mmu_set_halt - set CIO gate halt bit + * @mmu: MMU to set the CIO gate bit in. + * @halt: Desired state of the gate bit. + * + * This function sets the CIO gate bit that controls whether external memory + * accesses are allowed. Must be called when the hardware is powered on. + */ +static void ipu3_mmu_set_halt(struct ipu3_mmu *mmu, bool halt) +{ + int ret; + u32 val; + + writel(halt, mmu->base + REG_GP_HALT); + ret = readl_poll_timeout(mmu->base + REG_GP_HALTED, +val, (val & 1) == halt, 1000, 10); + + if (ret) + dev_err(mmu->dev, "failed to %s CIO gate halt\n", + halt ? "set" : "clear"); +} + +/** + * ipu3_mmu_alloc_page_table - allocate a pre-filled page table + * @pteval: Value to initialize for page table entries with. + * + * Return: Pointer to allocated page table or NULL on failure. + */ +static u32 *ipu3_mmu_alloc_page_table(u32 pteval) +{ + u32 *pt; + int pte; + + pt = (u32 *)__get_free_page(GFP_KERNEL); + if (!pt) + return NULL; + + for (pte = 0; pte < IPU3_PT_PTES; pte++) + pt[pte] = pteval; + + set_memory_uc((unsigned long int)pt, IPU3_PT_ORDER); + + return pt; +} + +/** + * ipu3_mmu_free_page_table - free page table + * @pt: Page table to free. + */ +static void ipu3_mmu_free_page_table(u32 *pt) +{ + set_memory_wb((unsigned long int)pt, IPU3_PT_ORDER); + free_page((unsigned long)pt); +} + +/** + * address_to_pte_idx - spli
[PATCH v6 06/12] intel-ipu3: css: Add support for firmware management
Introduce functions to load and install ImgU FW blobs. Signed-off-by: Yong Zhi --- drivers/media/pci/intel/ipu3/ipu3-abi.h| 1888 drivers/media/pci/intel/ipu3/ipu3-css-fw.c | 261 drivers/media/pci/intel/ipu3/ipu3-css-fw.h | 198 +++ 3 files changed, 2347 insertions(+) create mode 100644 drivers/media/pci/intel/ipu3/ipu3-abi.h create mode 100644 drivers/media/pci/intel/ipu3/ipu3-css-fw.c create mode 100644 drivers/media/pci/intel/ipu3/ipu3-css-fw.h diff --git a/drivers/media/pci/intel/ipu3/ipu3-abi.h b/drivers/media/pci/intel/ipu3/ipu3-abi.h new file mode 100644 index ..24102647a89e --- /dev/null +++ b/drivers/media/pci/intel/ipu3/ipu3-abi.h @@ -0,0 +1,1888 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* Copyright (C) 2018 Intel Corporation */ + +#ifndef __IPU3_ABI_H +#define __IPU3_ABI_H + +#include + +/*** IMGU Hardware information ***/ + +typedef __u32 imgu_addr_t; + +#define IMGU_ISP_VMEM_ALIGN128 +#define IMGU_DVS_BLOCK_W 64 +#define IMGU_DVS_BLOCK_H 32 +#define IMGU_GDC_BUF_X (2 * IMGU_DVS_BLOCK_W) +#define IMGU_GDC_BUF_Y IMGU_DVS_BLOCK_H +/* n = 0..1 */ +#define IMGU_SP_PMEM_BASE(n) (0x2 + (n) * 0x4000) +#define IMGU_MAX_BQ_GRID_WIDTH 80 +#define IMGU_MAX_BQ_GRID_HEIGHT60 +#define IMGU_OBGRID_TILE_SIZE 16 +#define IMGU_PIXELS_PER_WORD 50 +#define IMGU_BYTES_PER_WORD64 +#define IMGU_STRIPE_FIXED_HALF_OVERLAP 2 +#define IMGU_SHD_SETS 3 +#define IMGU_BDS_MIN_CLIP_VAL 0 +#define IMGU_BDS_MAX_CLIP_VAL 2 + +#define IMGU_ABI_AWB_MAX_CELLS_PER_SET 160 +#define IMGU_ABI_AF_MAX_CELLS_PER_SET 32 +#define IMGU_ABI_AWB_FR_MAX_CELLS_PER_SET 32 + +#define IMGU_ABI_ACC_OP_IDLE 0 +#define IMGU_ABI_ACC_OP_END_OF_ACK 1 +#define IMGU_ABI_ACC_OP_END_OF_OPS 2 +#define IMGU_ABI_ACC_OP_NO_OPS 3 + +#define IMGU_ABI_ACC_OPTYPE_PROCESS_LINES 0 +#define IMGU_ABI_ACC_OPTYPE_TRANSFER_DATA 1 + +/* Register definitions */ + +/* PM_CTRL_0_5_0_IMGHMMADR */ +#define IMGU_REG_PM_CTRL 0x0 +#define IMGU_PM_CTRL_START BIT(0) +#define IMGU_PM_CTRL_CFG_DONE BIT(1) +#define IMGU_PM_CTRL_RACE_TO_HALT BIT(2) +#define IMGU_PM_CTRL_NACK_ALL BIT(3) +#define IMGU_PM_CTRL_CSS_PWRDN BIT(4) +#define IMGU_PM_CTRL_RST_AT_EOFBIT(5) +#define IMGU_PM_CTRL_FORCE_HALTBIT(6) +#define IMGU_PM_CTRL_FORCE_UNHALT BIT(7) +#define IMGU_PM_CTRL_FORCE_PWRDN BIT(8) +#define IMGU_PM_CTRL_FORCE_RESET BIT(9) + +/* SYSTEM_REQ_0_5_0_IMGHMMADR */ +#define IMGU_REG_SYSTEM_REQ0x18 +#define IMGU_SYSTEM_REQ_FREQ_MASK 0x3f +#define IMGU_SYSTEM_REQ_FREQ_DIVIDER 25 +#define IMGU_REG_INT_STATUS0x30 +#define IMGU_REG_INT_ENABLE0x34 +#define IMGU_REG_INT_CSS_IRQ (1 << 31) +/* STATE_0_5_0_IMGHMMADR */ +#define IMGU_REG_STATE 0x130 +#define IMGU_STATE_HALT_STSBIT(0) +#define IMGU_STATE_IDLE_STSBIT(1) +#define IMGU_STATE_POWER_UPBIT(2) +#define IMGU_STATE_POWER_DOWN BIT(3) +#define IMGU_STATE_CSS_BUSY_MASK 0xc0 +#define IMGU_STATE_PM_FSM_MASK 0x180 +#define IMGU_STATE_PWRDNM_FSM_MASK 0x1E0 +/* PM_STS_0_5_0_IMGHMMADR */ +#define IMGU_REG_PM_STS0x140 + +#define IMGU_REG_BASE 0x4000 + +#define IMGU_REG_ISP_CTRL (IMGU_REG_BASE + 0x00) +#define IMGU_CTRL_RST BIT(0) +#define IMGU_CTRL_STARTBIT(1) +#define IMGU_CTRL_BREAKBIT(2) +#define IMGU_CTRL_RUN BIT(3) +#define IMGU_CTRL_BROKEN BIT(4) +#define IMGU_CTRL_IDLE BIT(5) +#define IMGU_CTRL_SLEEPING BIT(6) +#define IMGU_CTRL_STALLING BIT(7) +#define IMGU_CTRL_IRQ_CLEARBIT(8) +#define IMGU_CTRL_IRQ_READYBIT(10) +#define IMGU_CTRL_IRQ_SLEEPING BIT(11) +#define IMGU_CTRL_ICACHE_INV BIT(12) +#define IMGU_CTRL_IPREFETCH_EN BIT(13) +#define IMGU_REG_ISP_START_ADDR(IMGU_REG_BASE + 0x04) +#define IMGU_REG_ISP_ICACHE_ADDR (IMGU_REG_BASE + 0x10) +#define IMGU_REG_ISP_PC(IMGU_REG_BASE + 0x1c) + +/* SP Registers,
[PATCH v6 00/12] Intel IPU3 ImgU patchset
orted) Codec ioctls: test VIDIOC_(TRY_)ENCODER_CMD: OK (Not Supported) test VIDIOC_G_ENC_INDEX: OK (Not Supported) test VIDIOC_(TRY_)DECODER_CMD: OK (Not Supported) Buffer ioctls: test VIDIOC_REQBUFS/CREATE_BUFS/QUERYBUF: OK test VIDIOC_EXPBUF: OK Total: 353, Succeeded: 353, Failed: 0, Warnings: 0 Note: v4l2-compliance stream test was not performed as some manual steps are needed to pre-configure the media pipleline. Tomasz Figa (2): intel-ipu3: mmu: Implement driver intel-ipu3: Implement DMA mapping functions Yong Zhi (10): v4l: Add Intel IPU3 meta buffer formats intel-ipu3: Add user space API definitions intel-ipu3: css: Add dma buff pool utility functions intel-ipu3: css: Add support for firmware management intel-ipu3: css: Add static settings for image pipeline intel-ipu3: css: Compute and program ccs intel-ipu3: css: Initialize css hardware intel-ipu3: Add css pipeline programming intel-ipu3: Add v4l2 driver based on media framework intel-ipu3: Add imgu top level pci device driver drivers/media/pci/intel/ipu3/Kconfig | 14 + drivers/media/pci/intel/ipu3/Makefile | 11 + drivers/media/pci/intel/ipu3/ipu3-abi.h| 1888 + drivers/media/pci/intel/ipu3/ipu3-css-fw.c | 261 + drivers/media/pci/intel/ipu3/ipu3-css-fw.h | 198 + drivers/media/pci/intel/ipu3/ipu3-css-params.c | 2890 +++ drivers/media/pci/intel/ipu3/ipu3-css-params.h | 25 + drivers/media/pci/intel/ipu3/ipu3-css-pool.c | 131 + drivers/media/pci/intel/ipu3/ipu3-css-pool.h | 36 + drivers/media/pci/intel/ipu3/ipu3-css.c| 2289 ++ drivers/media/pci/intel/ipu3/ipu3-css.h| 205 + drivers/media/pci/intel/ipu3/ipu3-dmamap.c | 280 + drivers/media/pci/intel/ipu3/ipu3-dmamap.h | 22 + drivers/media/pci/intel/ipu3/ipu3-mmu.c| 560 ++ drivers/media/pci/intel/ipu3/ipu3-mmu.h| 28 + drivers/media/pci/intel/ipu3/ipu3-tables.c | 9609 drivers/media/pci/intel/ipu3/ipu3-tables.h | 66 + drivers/media/pci/intel/ipu3/ipu3-v4l2.c | 1089 +++ drivers/media/pci/intel/ipu3/ipu3.c| 849 +++ drivers/media/pci/intel/ipu3/ipu3.h| 151 + drivers/media/v4l2-core/v4l2-ioctl.c |2 + include/uapi/linux/intel-ipu3.h| 1403 include/uapi/linux/videodev2.h |4 + 23 files changed, 22011 insertions(+) create mode 100644 drivers/media/pci/intel/ipu3/ipu3-abi.h create mode 100644 drivers/media/pci/intel/ipu3/ipu3-css-fw.c create mode 100644 drivers/media/pci/intel/ipu3/ipu3-css-fw.h create mode 100644 drivers/media/pci/intel/ipu3/ipu3-css-params.c create mode 100644 drivers/media/pci/intel/ipu3/ipu3-css-params.h create mode 100644 drivers/media/pci/intel/ipu3/ipu3-css-pool.c create mode 100644 drivers/media/pci/intel/ipu3/ipu3-css-pool.h create mode 100644 drivers/media/pci/intel/ipu3/ipu3-css.c create mode 100644 drivers/media/pci/intel/ipu3/ipu3-css.h create mode 100644 drivers/media/pci/intel/ipu3/ipu3-dmamap.c create mode 100644 drivers/media/pci/intel/ipu3/ipu3-dmamap.h create mode 100644 drivers/media/pci/intel/ipu3/ipu3-mmu.c create mode 100644 drivers/media/pci/intel/ipu3/ipu3-mmu.h create mode 100644 drivers/media/pci/intel/ipu3/ipu3-tables.c create mode 100644 drivers/media/pci/intel/ipu3/ipu3-tables.h create mode 100644 drivers/media/pci/intel/ipu3/ipu3-v4l2.c create mode 100644 drivers/media/pci/intel/ipu3/ipu3.c create mode 100644 drivers/media/pci/intel/ipu3/ipu3.h create mode 100644 include/uapi/linux/intel-ipu3.h -- 2.7.4
[PATCH 08/12] intel-ipu3: css: Compute and program ccs
A collection of routines that are mainly used to calculate the parameters for accelerator cluster. Signed-off-by: Yong Zhi --- drivers/media/pci/intel/ipu3/ipu3-css-params.c | 2890 drivers/media/pci/intel/ipu3/ipu3-css-params.h | 25 + drivers/media/pci/intel/ipu3/ipu3-css.h| 205 ++ 3 files changed, 3120 insertions(+) create mode 100644 drivers/media/pci/intel/ipu3/ipu3-css-params.c create mode 100644 drivers/media/pci/intel/ipu3/ipu3-css-params.h create mode 100644 drivers/media/pci/intel/ipu3/ipu3-css.h diff --git a/drivers/media/pci/intel/ipu3/ipu3-css-params.c b/drivers/media/pci/intel/ipu3/ipu3-css-params.c new file mode 100644 index ..0492a87868ec --- /dev/null +++ b/drivers/media/pci/intel/ipu3/ipu3-css-params.c @@ -0,0 +1,2890 @@ +// SPDX-License-Identifier: GPL-2.0 +// Copyright (C) 2018 Intel Corporation + +#include + +#include "ipu3-css.h" +#include "ipu3-css-fw.h" +#include "ipu3-tables.h" + +#define sqr(x) ((x) * (x)) +#define DIV_ROUND_CLOSEST_DOWN(a, b) (((a) + ((b) / 2) - 1) / (b)) +#define roundclosest_down(a, b)(DIV_ROUND_CLOSEST_DOWN(a, b) * (b)) + +struct ipu3_css_scaler_info { + unsigned int phase_step;/* Same for luma/chroma */ + int exp_shift; + + unsigned int phase_init;/* luma/chroma dependent */ + int pad_left; + int pad_right; + int crop_left; + int crop_top; +}; + +static unsigned int ipu3_css_scaler_get_exp(unsigned int counter, + unsigned int divider) +{ + int i = fls(divider) - fls(counter); + + if (i <= 0) + return 0; + + if (divider >> i < counter) + i = i - 1; + + return i; +} + +/* Set up the CSS scaler look up table */ +static void +ipu3_css_scaler_setup_lut(unsigned int taps, unsigned int input_width, + unsigned int output_width, int phase_step_correction, + const int *coeffs, unsigned int coeffs_size, + s8 coeff_lut[], struct ipu3_css_scaler_info *info) +{ + int tap, phase, phase_sum_left, phase_sum_right; + int exponent = ipu3_css_scaler_get_exp(output_width, input_width); + int mantissa = (1 << exponent) * output_width; + unsigned int phase_step; + + if (input_width == output_width) { + for (phase = 0; phase < IMGU_SCALER_PHASES; phase++) { + for (tap = 0; tap < taps; tap++) { + coeff_lut[phase * IMGU_SCALER_FILTER_TAPS + tap] + = 0; + } + } + + info->phase_step = IMGU_SCALER_PHASES * + (1 << IMGU_SCALER_PHASE_COUNTER_PREC_REF); + info->exp_shift = 0; + info->pad_left = 0; + info->pad_right = 0; + info->phase_init = 0; + info->crop_left = 0; + info->crop_top = 0; + return; + } + + for (phase = 0; phase < IMGU_SCALER_PHASES; phase++) { + for (tap = 0; tap < taps; tap++) { + /* flip table to for convolution reverse indexing */ + s64 coeff = coeffs[coeffs_size - + ((tap * (coeffs_size / taps)) + phase) - 1]; + coeff *= mantissa; + coeff = div64_long(coeff, input_width); + + /* Add +"0.5" */ + coeff += 1 << (IMGU_SCALER_COEFF_BITS - 1); + coeff >>= IMGU_SCALER_COEFF_BITS; + + coeff_lut[phase * IMGU_SCALER_FILTER_TAPS + tap] = + coeff; + } + } + + phase_step = IMGU_SCALER_PHASES * + (1 << IMGU_SCALER_PHASE_COUNTER_PREC_REF) * + output_width / input_width; + phase_step += phase_step_correction; + phase_sum_left = (taps / 2 * IMGU_SCALER_PHASES * + (1 << IMGU_SCALER_PHASE_COUNTER_PREC_REF)) - + (1 << (IMGU_SCALER_PHASE_COUNTER_PREC_REF - 1)); + phase_sum_right = (taps / 2 * IMGU_SCALER_PHASES * + (1 << IMGU_SCALER_PHASE_COUNTER_PREC_REF)) + + (1 << (IMGU_SCALER_PHASE_COUNTER_PREC_REF - 1)); + + info->exp_shift = IMGU_SCALER_MAX_EXPONENT_SHIFT - exponent; + info->pad_left = (phase_sum_left % phase_step == 0) ? + phase_sum_left / phase_step - 1 : phase_sum_left / phase_step; + info->pad_right = (phase_sum_right % phase_step == 0) ? + phase_sum_right / phase_step - 1 : phase_sum_right / phase_step; + info->phase_init = pha
[PATCH v6 09/12] intel-ipu3: css: Initialize css hardware
This patch implements the functions to initialize and configure IPU3 h/w such as clock, irq and power. Signed-off-by: Yong Zhi Signed-off-by: Tomasz Figa --- drivers/media/pci/intel/ipu3/ipu3-css.c | 537 1 file changed, 537 insertions(+) create mode 100644 drivers/media/pci/intel/ipu3/ipu3-css.c diff --git a/drivers/media/pci/intel/ipu3/ipu3-css.c b/drivers/media/pci/intel/ipu3/ipu3-css.c new file mode 100644 index ..164830fc91ad --- /dev/null +++ b/drivers/media/pci/intel/ipu3/ipu3-css.c @@ -0,0 +1,537 @@ +// SPDX-License-Identifier: GPL-2.0 +// Copyright (C) 2018 Intel Corporation + +#include +#include + +#include "ipu3-css.h" +#include "ipu3-css-fw.h" +#include "ipu3-css-params.h" +#include "ipu3-dmamap.h" +#include "ipu3-tables.h" + +/* IRQ configuration */ +#define IMGU_IRQCTRL_IRQ_MASK (IMGU_IRQCTRL_IRQ_SP1 | \ +IMGU_IRQCTRL_IRQ_SP2 | \ +IMGU_IRQCTRL_IRQ_SW_PIN(0) | \ +IMGU_IRQCTRL_IRQ_SW_PIN(1)) + +/*** css hw ***/ + +/* In the style of writesl() defined in include/asm-generic/io.h */ +static inline void writes(const void *mem, ssize_t count, void __iomem *addr) +{ + if (count >= 4) { + const u32 *buf = mem; + + count /= 4; + do { + writel(*buf++, addr); + addr += 4; + } while (--count); + } +} + +/* Wait until register `reg', masked with `mask', becomes `cmp' */ +static int ipu3_hw_wait(void __iomem *base, int reg, u32 mask, u32 cmp) +{ + u32 val; + + return readl_poll_timeout(base + reg, val, (val & mask) == cmp, + 1000, 100 * 1000); +} + +/* Initialize the IPU3 CSS hardware and associated h/w blocks */ + +int ipu3_css_set_powerup(struct device *dev, void __iomem *base) +{ + static const unsigned int freq = 450; + u32 pm_ctrl, state, val; + + dev_dbg(dev, "%s\n", __func__); + /* Clear the CSS busy signal */ + readl(base + IMGU_REG_GP_BUSY); + writel(0, base + IMGU_REG_GP_BUSY); + + /* Wait for idle signal */ + if (ipu3_hw_wait(base, IMGU_REG_STATE, IMGU_STATE_IDLE_STS, +IMGU_STATE_IDLE_STS)) { + dev_err(dev, "failed to set CSS idle\n"); + goto fail; + } + + /* Reset the css */ + writel(readl(base + IMGU_REG_PM_CTRL) | IMGU_PM_CTRL_FORCE_RESET, + base + IMGU_REG_PM_CTRL); + + usleep_range(200, 300); + + /** Prepare CSS */ + + pm_ctrl = readl(base + IMGU_REG_PM_CTRL); + state = readl(base + IMGU_REG_STATE); + + dev_dbg(dev, "CSS pm_ctrl 0x%x state 0x%x (power %s)\n", + pm_ctrl, state, state & IMGU_STATE_POWER_DOWN ? "down" : "up"); + + /* Power up CSS using wrapper */ + if (state & IMGU_STATE_POWER_DOWN) { + writel(IMGU_PM_CTRL_RACE_TO_HALT | IMGU_PM_CTRL_START, + base + IMGU_REG_PM_CTRL); + if (ipu3_hw_wait(base, IMGU_REG_PM_CTRL, +IMGU_PM_CTRL_START, 0)) { + dev_err(dev, "failed to power up CSS\n"); + goto fail; + } + usleep_range(2000, 3000); + } else { + writel(IMGU_PM_CTRL_RACE_TO_HALT, base + IMGU_REG_PM_CTRL); + } + + /* Set the busy bit */ + writel(readl(base + IMGU_REG_GP_BUSY) | 1, base + IMGU_REG_GP_BUSY); + + /* Set CSS clock frequency */ + pm_ctrl = readl(base + IMGU_REG_PM_CTRL); + val = pm_ctrl & ~(IMGU_PM_CTRL_CSS_PWRDN | IMGU_PM_CTRL_RST_AT_EOF); + writel(val, base + IMGU_REG_PM_CTRL); + writel(0, base + IMGU_REG_GP_BUSY); + if (ipu3_hw_wait(base, IMGU_REG_STATE, +IMGU_STATE_PWRDNM_FSM_MASK, 0)) { + dev_err(dev, "failed to pwrdn CSS\n"); + goto fail; + } + val = (freq / IMGU_SYSTEM_REQ_FREQ_DIVIDER) & IMGU_SYSTEM_REQ_FREQ_MASK; + writel(val, base + IMGU_REG_SYSTEM_REQ); + writel(1, base + IMGU_REG_GP_BUSY); + writel(readl(base + IMGU_REG_PM_CTRL) | IMGU_PM_CTRL_FORCE_HALT, + base + IMGU_REG_PM_CTRL); + if (ipu3_hw_wait(base, IMGU_REG_STATE, IMGU_STATE_HALT_STS, +IMGU_STATE_HALT_STS)) { + dev_err(dev, "failed to halt CSS\n"); + goto fail; + } + + writel(readl(base + IMGU_REG_PM_CTRL) | IMGU_PM_CTRL_START, + base + IMGU_REG_PM_CTRL); + if (ipu3_hw_wait(base, IMGU_REG_PM_CTRL, IMGU_PM_CTRL_START, 0)) { + dev_err(dev, "failed to start CSS\n"); + goto fail; +
[PATCH v6 12/12] intel-ipu3: Add imgu top level pci device driver
This patch adds support for the Intel IPU v3 as found on Skylake and Kaby Lake SoCs. The driver glues v4l2, css(camera sub system) and other pieces together to perform its functions, it also loads the IPU3 firmware binary as part of its initialization. Signed-off-by: Yong Zhi Signed-off-by: Tomasz Figa --- drivers/media/pci/intel/ipu3/Kconfig | 14 + drivers/media/pci/intel/ipu3/Makefile | 11 + drivers/media/pci/intel/ipu3/ipu3.c | 849 ++ 3 files changed, 874 insertions(+) create mode 100644 drivers/media/pci/intel/ipu3/ipu3.c diff --git a/drivers/media/pci/intel/ipu3/Kconfig b/drivers/media/pci/intel/ipu3/Kconfig index a82d3fe277d2..a844735cab2e 100644 --- a/drivers/media/pci/intel/ipu3/Kconfig +++ b/drivers/media/pci/intel/ipu3/Kconfig @@ -17,3 +17,17 @@ config VIDEO_IPU3_CIO2 Say Y or M here if you have a Skylake/Kaby Lake SoC with MIPI CSI-2 connected camera. The module will be called ipu3-cio2. + +config VIDEO_IPU3_IMGU + tristate "Intel ipu3-imgu driver" + depends on PCI && VIDEO_V4L2 + depends on MEDIA_CONTROLLER && VIDEO_V4L2_SUBDEV_API + select IOMMU_IOVA + select VIDEOBUF2_DMA_SG + ---help--- + This is the video4linux2 driver for Intel IPU3 image processing unit, + found in Intel Skylake and Kaby Lake SoCs and used for processing + images and video. + + Say Y or M here if you have a Skylake/Kaby Lake SoC with a MIPI + camera. The module will be called ipu3-imgu. diff --git a/drivers/media/pci/intel/ipu3/Makefile b/drivers/media/pci/intel/ipu3/Makefile index 20186e3ff2ae..dbfe37db3412 100644 --- a/drivers/media/pci/intel/ipu3/Makefile +++ b/drivers/media/pci/intel/ipu3/Makefile @@ -1 +1,12 @@ +# +# Makefile for the IPU3 cio2 and ImgU drivers +# + obj-$(CONFIG_VIDEO_IPU3_CIO2) += ipu3-cio2.o + +ipu3-imgu-objs += ipu3-mmu.o ipu3-dmamap.o \ + ipu3-tables.o ipu3-css-pool.o \ + ipu3-css-fw.o ipu3-css-params.o \ + ipu3-css.o ipu3-v4l2.o ipu3.o + +obj-$(CONFIG_VIDEO_IPU3_IMGU) += ipu3-imgu.o diff --git a/drivers/media/pci/intel/ipu3/ipu3.c b/drivers/media/pci/intel/ipu3/ipu3.c new file mode 100644 index ..c2fb0ab3bd6d --- /dev/null +++ b/drivers/media/pci/intel/ipu3/ipu3.c @@ -0,0 +1,849 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (C) 2017 Intel Corporation + * Copyright (C) 2017 Google, Inc. + * + * Based on Intel IPU4 driver. + * + */ + +#include +#include +#include +#include + +#include "ipu3.h" +#include "ipu3-dmamap.h" +#include "ipu3-mmu.h" + +#define IMGU_PCI_ID0x1919 +#define IMGU_PCI_BAR 0 +#define IMGU_DMA_MASK DMA_BIT_MASK(39) +#define IMGU_MAX_QUEUE_DEPTH (2 + 2) + +/* + * pre-allocated buffer size for IMGU dummy buffers. Those + * values should be tuned to big enough to avoid buffer + * re-allocation when streaming to lower streaming latency. + */ +#define CSS_QUEUE_IN_BUF_SIZE 0 +#define CSS_QUEUE_PARAMS_BUF_SIZE 0 +#define CSS_QUEUE_OUT_BUF_SIZE (4160 * 3120 * 12 / 8) +#define CSS_QUEUE_VF_BUF_SIZE (1920 * 1080 * 12 / 8) +#define CSS_QUEUE_STAT_3A_BUF_SIZE 125664 + +static const size_t css_queue_buf_size_map[IPU3_CSS_QUEUES] = { + [IPU3_CSS_QUEUE_IN] = CSS_QUEUE_IN_BUF_SIZE, + [IPU3_CSS_QUEUE_PARAMS] = CSS_QUEUE_PARAMS_BUF_SIZE, + [IPU3_CSS_QUEUE_OUT] = CSS_QUEUE_OUT_BUF_SIZE, + [IPU3_CSS_QUEUE_VF] = CSS_QUEUE_VF_BUF_SIZE, + [IPU3_CSS_QUEUE_STAT_3A] = CSS_QUEUE_STAT_3A_BUF_SIZE, +}; + +static const struct imgu_node_mapping imgu_node_map[IMGU_NODE_NUM] = { + [IMGU_NODE_IN] = {IPU3_CSS_QUEUE_IN, "input"}, + [IMGU_NODE_PARAMS] = {IPU3_CSS_QUEUE_PARAMS, "parameters"}, + [IMGU_NODE_OUT] = {IPU3_CSS_QUEUE_OUT, "output"}, + [IMGU_NODE_VF] = {IPU3_CSS_QUEUE_VF, "viewfinder"}, + [IMGU_NODE_PV] = {IPU3_CSS_QUEUE_VF, "postview"}, + [IMGU_NODE_STAT_3A] = {IPU3_CSS_QUEUE_STAT_3A, "3a stat"}, +}; + +unsigned int imgu_node_to_queue(unsigned int node) +{ + return imgu_node_map[node].css_queue; +} + +unsigned int imgu_map_node(struct imgu_device *imgu, unsigned int css_queue) +{ + unsigned int i; + + if (css_queue == IPU3_CSS_QUEUE_VF) + return imgu->nodes[IMGU_NODE_VF].enabled ? + IMGU_NODE_VF : IMGU_NODE_PV; + + for (i = 0; i < IMGU_NODE_NUM; i++) + if (imgu_node_map[i].css_queue == css_queue) + break; + + return i; +} + +/ Dummy buffers / + +static void imgu_dummybufs_cleanup(struct imgu_device *imgu) +{ + unsigned int i; + + for (i = 0; i < IPU3_CSS_QUEUES; i++) + ipu3_dmamap_free(&imgu->pci_dev->dev, &imgu->queues[i].dmap);
[PATCH v6 10/12] intel-ipu3: Add css pipeline programming
This provides helper library to be used by v4l2 level to program imaging pipelines and control the streaming. Signed-off-by: Yong Zhi --- drivers/media/pci/intel/ipu3/ipu3-css.c | 1752 +++ 1 file changed, 1752 insertions(+) diff --git a/drivers/media/pci/intel/ipu3/ipu3-css.c b/drivers/media/pci/intel/ipu3/ipu3-css.c index 164830fc91ad..48fbc037c4a3 100644 --- a/drivers/media/pci/intel/ipu3/ipu3-css.c +++ b/drivers/media/pci/intel/ipu3/ipu3-css.c @@ -16,6 +16,173 @@ IMGU_IRQCTRL_IRQ_SW_PIN(0) | \ IMGU_IRQCTRL_IRQ_SW_PIN(1)) +#define IPU3_CSS_FORMAT_BPP_DEN50 /* Denominator */ + +/* Some sane limits for resolutions */ +#define IPU3_CSS_MIN_RES 32 +#define IPU3_CSS_MAX_H 3136 +#define IPU3_CSS_MAX_W 4224 + +/* filter size from graph settings is fixed as 4 */ +#define FILTER_SIZE 4 +#define MIN_ENVELOPE8 + +/* + * pre-allocated buffer size for CSS ABI, auxiliary frames + * after BDS and before GDC. Those values should be tuned + * to big enough to avoid buffer re-allocation when + * streaming to lower streaming latency. + */ +#define CSS_ABI_SIZE136 +#define CSS_BDS_SIZE(4480 * 3200 * 3) +#define CSS_GDC_SIZE(4224 * 3200 * 12 / 8) + +#define IPU3_CSS_QUEUE_TO_FLAGS(q) (1 << (q)) +#define IPU3_CSS_FORMAT_FL_IN \ + IPU3_CSS_QUEUE_TO_FLAGS(IPU3_CSS_QUEUE_IN) +#define IPU3_CSS_FORMAT_FL_OUT \ + IPU3_CSS_QUEUE_TO_FLAGS(IPU3_CSS_QUEUE_OUT) +#define IPU3_CSS_FORMAT_FL_VF \ + IPU3_CSS_QUEUE_TO_FLAGS(IPU3_CSS_QUEUE_VF) + +/* Formats supported by IPU3 Camera Sub System */ +static const struct ipu3_css_format ipu3_css_formats[] = { + { + .pixelformat = V4L2_PIX_FMT_NV12, + .colorspace = V4L2_COLORSPACE_SRGB, + .frame_format = IMGU_ABI_FRAME_FORMAT_NV12, + .osys_format = IMGU_ABI_OSYS_FORMAT_NV12, + .osys_tiling = IMGU_ABI_OSYS_TILING_NONE, + .bytesperpixel_num = 1 * IPU3_CSS_FORMAT_BPP_DEN, + .chroma_decim = 4, + .width_align = IPU3_UAPI_ISP_VEC_ELEMS, + .flags = IPU3_CSS_FORMAT_FL_OUT | IPU3_CSS_FORMAT_FL_VF, + }, { + /* Each 32 bytes contains 25 10-bit pixels */ + .pixelformat = V4L2_PIX_FMT_IPU3_SBGGR10, + .colorspace = V4L2_COLORSPACE_RAW, + .frame_format = IMGU_ABI_FRAME_FORMAT_RAW_PACKED, + .bayer_order = IMGU_ABI_BAYER_ORDER_BGGR, + .bit_depth = 10, + .bytesperpixel_num = 64, + .width_align = 2 * IPU3_UAPI_ISP_VEC_ELEMS, + .flags = IPU3_CSS_FORMAT_FL_IN, + }, { + .pixelformat = V4L2_PIX_FMT_IPU3_SGBRG10, + .colorspace = V4L2_COLORSPACE_RAW, + .frame_format = IMGU_ABI_FRAME_FORMAT_RAW_PACKED, + .bayer_order = IMGU_ABI_BAYER_ORDER_GBRG, + .bit_depth = 10, + .bytesperpixel_num = 64, + .width_align = 2 * IPU3_UAPI_ISP_VEC_ELEMS, + .flags = IPU3_CSS_FORMAT_FL_IN, + }, { + .pixelformat = V4L2_PIX_FMT_IPU3_SGRBG10, + .colorspace = V4L2_COLORSPACE_RAW, + .frame_format = IMGU_ABI_FRAME_FORMAT_RAW_PACKED, + .bayer_order = IMGU_ABI_BAYER_ORDER_GRBG, + .bit_depth = 10, + .bytesperpixel_num = 64, + .width_align = 2 * IPU3_UAPI_ISP_VEC_ELEMS, + .flags = IPU3_CSS_FORMAT_FL_IN, + }, { + .pixelformat = V4L2_PIX_FMT_IPU3_SRGGB10, + .colorspace = V4L2_COLORSPACE_RAW, + .frame_format = IMGU_ABI_FRAME_FORMAT_RAW_PACKED, + .bayer_order = IMGU_ABI_BAYER_ORDER_RGGB, + .bit_depth = 10, + .bytesperpixel_num = 64, + .width_align = 2 * IPU3_UAPI_ISP_VEC_ELEMS, + .flags = IPU3_CSS_FORMAT_FL_IN, + }, +}; + +static const struct { + enum imgu_abi_queue_id qid; + size_t ptr_ofs; +} ipu3_css_queues[IPU3_CSS_QUEUES] = { + [IPU3_CSS_QUEUE_IN] = { + IMGU_ABI_QUEUE_C_ID, + offsetof(struct imgu_abi_buffer, payload.frame.frame_data) + }, + [IPU3_CSS_QUEUE_OUT] = { + IMGU_ABI_QUEUE_D_ID, + offsetof(struct imgu_abi_buffer, payload.frame.frame_data) + }, + [IPU3_CSS_QUEUE_VF] = { + IMGU_ABI_QUEUE_E_ID, + offsetof(struct imgu_abi_buffer, payload.frame.frame_data) + }, + [IPU3_CSS_QUEUE_STAT_3A] = { + IMGU_ABI_QUEUE_F_ID, + offsetof(struct imgu_abi_buffer, payload.s3a.data_ptr) + }, +}; + +/* Initialize queue based on given format, adjust format as needed */ +static int ipu3_css_queue_init(struct ipu3_css