Re: [PATCH v7 09/16] intel-ipu3: css: Add support for firmware management

2018-11-28 Thread Sakari Ailus
Hi Yong,

On Mon, Oct 29, 2018 at 03:23:03PM -0700, Yong Zhi wrote:
...
> diff --git a/drivers/media/pci/intel/ipu3/ipu3-css-fw.h 
> b/drivers/media/pci/intel/ipu3/ipu3-css-fw.h
> new file mode 100644
> index 000..954bb31
> --- /dev/null
> +++ b/drivers/media/pci/intel/ipu3/ipu3-css-fw.h
> @@ -0,0 +1,188 @@
> +/* SPDX-License-Identifier: GPL-2.0 */
> +/* Copyright (C) 2018 Intel Corporation */
> +
> +#ifndef __IPU3_CSS_FW_H
> +#define __IPU3_CSS_FW_H
> +
> +/*** Firmware file definitions ***/
> +
> +#define IMGU_FW_NAME "ipu3-fw.bin"

Shouldn't this be "intel/ipu3-fw.bin"?

-- 
Sakari Ailus
sakari.ai...@linux.intel.com


[PATCH v7 09/16] intel-ipu3: css: Add support for firmware management

2018-10-29 Thread Yong Zhi
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 (css->fw)
+   release_firmware(css->fw);
+
+   css->binary = NULL;
+   css->fw = NULL;
+}
+
+int ipu3_css_fw_init(struct ipu3_css *css)
+{
+   static const u32 BLOCK_MAX = 65536;
+   struct imgu_device *imgu = dev_get_drvdata(css->dev);
+   struct device *dev = css->dev;
+   unsigned int i, j, binary_nr;
+   int r;
+
+