linux/drivers/staging/media/atomisp/pci/ia_css_frame_public.h
<<
>>
Prefs
   1/* SPDX-License-Identifier: GPL-2.0 */
   2/*
   3 * Support for Intel Camera Imaging ISP subsystem.
   4 * Copyright (c) 2015, Intel Corporation.
   5 *
   6 * This program is free software; you can redistribute it and/or modify it
   7 * under the terms and conditions of the GNU General Public License,
   8 * version 2, as published by the Free Software Foundation.
   9 *
  10 * This program is distributed in the hope it will be useful, but WITHOUT
  11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
  13 * more details.
  14 */
  15
  16#ifndef __IA_CSS_FRAME_PUBLIC_H
  17#define __IA_CSS_FRAME_PUBLIC_H
  18
  19/* @file
  20 * This file contains structs to describe various frame-formats supported by the ISP.
  21 */
  22
  23#include <type_support.h>
  24#include "ia_css_err.h"
  25#include "ia_css_types.h"
  26#include "ia_css_frame_format.h"
  27#include "ia_css_buffer.h"
  28
  29/* For RAW input, the bayer order needs to be specified separately. There
  30 *  are 4 possible orders. The name is constructed by taking the first two
  31 *  colors on the first line and the first two colors from the second line.
  32 */
  33enum ia_css_bayer_order {
  34        IA_CSS_BAYER_ORDER_GRBG, /** GRGRGRGRGR .. BGBGBGBGBG */
  35        IA_CSS_BAYER_ORDER_RGGB, /** RGRGRGRGRG .. GBGBGBGBGB */
  36        IA_CSS_BAYER_ORDER_BGGR, /** BGBGBGBGBG .. GRGRGRGRGR */
  37        IA_CSS_BAYER_ORDER_GBRG, /** GBGBGBGBGB .. RGRGRGRGRG */
  38};
  39
  40#define IA_CSS_BAYER_ORDER_NUM (IA_CSS_BAYER_ORDER_GBRG + 1)
  41
  42/* Frame plane structure. This describes one plane in an image
  43 *  frame buffer.
  44 */
  45struct ia_css_frame_plane {
  46        unsigned int height; /** height of a plane in lines */
  47        unsigned int width;  /** width of a line, in DMA elements, note that
  48                                  for RGB565 the three subpixels are stored in
  49                                  one element. For all other formats this is
  50                                  the number of subpixels per line. */
  51        unsigned int stride; /** stride of a line in bytes */
  52        unsigned int offset; /** offset in bytes to start of frame data.
  53                                  offset is wrt data field in ia_css_frame */
  54};
  55
  56/* Binary "plane". This is used to story binary streams such as jpeg
  57 *  images. This is not actually a real plane.
  58 */
  59struct ia_css_frame_binary_plane {
  60        unsigned int              size; /** number of bytes in the stream */
  61        struct ia_css_frame_plane data; /** plane */
  62};
  63
  64/* Container for planar YUV frames. This contains 3 planes.
  65 */
  66struct ia_css_frame_yuv_planes {
  67        struct ia_css_frame_plane y; /** Y plane */
  68        struct ia_css_frame_plane u; /** U plane */
  69        struct ia_css_frame_plane v; /** V plane */
  70};
  71
  72/* Container for semi-planar YUV frames.
  73  */
  74struct ia_css_frame_nv_planes {
  75        struct ia_css_frame_plane y;  /** Y plane */
  76        struct ia_css_frame_plane uv; /** UV plane */
  77};
  78
  79/* Container for planar RGB frames. Each color has its own plane.
  80 */
  81struct ia_css_frame_rgb_planes {
  82        struct ia_css_frame_plane r; /** Red plane */
  83        struct ia_css_frame_plane g; /** Green plane */
  84        struct ia_css_frame_plane b; /** Blue plane */
  85};
  86
  87/* Container for 6-plane frames. These frames are used internally
  88 *  in the advanced ISP only.
  89 */
  90struct ia_css_frame_plane6_planes {
  91        struct ia_css_frame_plane r;      /** Red plane */
  92        struct ia_css_frame_plane r_at_b; /** Red at blue plane */
  93        struct ia_css_frame_plane gr;     /** Red-green plane */
  94        struct ia_css_frame_plane gb;     /** Blue-green plane */
  95        struct ia_css_frame_plane b;      /** Blue plane */
  96        struct ia_css_frame_plane b_at_r; /** Blue at red plane */
  97};
  98
  99/* Crop info struct - stores the lines to be cropped in isp */
 100struct ia_css_crop_info {
 101        /* the final start column and start line
 102         * sum of lines to be cropped + bayer offset
 103         */
 104        unsigned int start_column;
 105        unsigned int start_line;
 106};
 107
 108/* Frame info struct. This describes the contents of an image frame buffer.
 109  */
 110struct ia_css_frame_info {
 111        struct ia_css_resolution res; /** Frame resolution (valid data) */
 112        unsigned int padded_width; /** stride of line in memory (in pixels) */
 113        enum ia_css_frame_format format; /** format of the frame data */
 114        unsigned int raw_bit_depth; /** number of valid bits per pixel,
 115                                         only valid for RAW bayer frames */
 116        enum ia_css_bayer_order raw_bayer_order; /** bayer order, only valid
 117                                                      for RAW bayer frames */
 118        /* the params below are computed based on bayer_order
 119         * we can remove the raw_bayer_order if it is redundant
 120         * keeping it for now as bxt and fpn code seem to use it
 121         */
 122        struct ia_css_crop_info crop_info;
 123};
 124
 125#define IA_CSS_BINARY_DEFAULT_FRAME_INFO { \
 126        .format                 = IA_CSS_FRAME_FORMAT_NUM,  \
 127        .raw_bayer_order        = IA_CSS_BAYER_ORDER_NUM, \
 128}
 129
 130/**
 131 *  Specifies the DVS loop delay in "frame periods"
 132 */
 133enum ia_css_frame_delay {
 134        IA_CSS_FRAME_DELAY_0, /** Frame delay = 0 */
 135        IA_CSS_FRAME_DELAY_1, /** Frame delay = 1 */
 136        IA_CSS_FRAME_DELAY_2  /** Frame delay = 2 */
 137};
 138
 139enum ia_css_frame_flash_state {
 140        IA_CSS_FRAME_FLASH_STATE_NONE,
 141        IA_CSS_FRAME_FLASH_STATE_PARTIAL,
 142        IA_CSS_FRAME_FLASH_STATE_FULL
 143};
 144
 145/* Frame structure. This structure describes an image buffer or frame.
 146 *  This is the main structure used for all input and output images.
 147 */
 148struct ia_css_frame {
 149        struct ia_css_frame_info info; /** info struct describing the frame */
 150        ia_css_ptr   data;             /** pointer to start of image data */
 151        unsigned int data_bytes;       /** size of image data in bytes */
 152        /* LA: move this to ia_css_buffer */
 153        /*
 154         * -1 if data address is static during life time of pipeline
 155         * >=0 if data address can change per pipeline/frame iteration
 156         *     index to dynamic data: ia_css_frame_in, ia_css_frame_out
 157         *                            ia_css_frame_out_vf
 158         *     index to host-sp queue id: queue_0, queue_1 etc.
 159         */
 160        int dynamic_queue_id;
 161        /*
 162         * if it is dynamic frame, buf_type indicates which buffer type it
 163         * should use for event generation. we have this because in vf_pp
 164         * binary, we use output port, but we expect VF_OUTPUT_DONE event
 165         */
 166        enum ia_css_buffer_type buf_type;
 167        enum ia_css_frame_flash_state flash_state;
 168        unsigned int exp_id;
 169        /** exposure id, see ia_css_event_public.h for more detail */
 170        u32 isp_config_id; /** Unique ID to track which config was actually applied to a particular frame */
 171        bool valid; /** First video output frame is not valid */
 172        bool contiguous; /** memory is allocated physically contiguously */
 173        union {
 174                unsigned int    _initialisation_dummy;
 175                struct ia_css_frame_plane raw;
 176                struct ia_css_frame_plane rgb;
 177                struct ia_css_frame_rgb_planes planar_rgb;
 178                struct ia_css_frame_plane yuyv;
 179                struct ia_css_frame_yuv_planes yuv;
 180                struct ia_css_frame_nv_planes nv;
 181                struct ia_css_frame_plane6_planes plane6;
 182                struct ia_css_frame_binary_plane binary;
 183        } planes; /** frame planes, select the right one based on
 184                       info.format */
 185};
 186
 187#define DEFAULT_FRAME { \
 188        .info                   = IA_CSS_BINARY_DEFAULT_FRAME_INFO, \
 189        .dynamic_queue_id       = SH_CSS_INVALID_QUEUE_ID, \
 190        .buf_type               = IA_CSS_BUFFER_TYPE_INVALID, \
 191        .flash_state            = IA_CSS_FRAME_FLASH_STATE_NONE, \
 192}
 193
 194/* @brief Fill a frame with zeros
 195 *
 196 * @param       frame           The frame.
 197 * @return      None
 198 *
 199 * Fill a frame with pixel values of zero
 200 */
 201void ia_css_frame_zero(struct ia_css_frame *frame);
 202
 203/* @brief Allocate a CSS frame structure
 204 *
 205 * @param       frame           The allocated frame.
 206 * @param       width           The width (in pixels) of the frame.
 207 * @param       height          The height (in lines) of the frame.
 208 * @param       format          The frame format.
 209 * @param       stride          The padded stride, in pixels.
 210 * @param       raw_bit_depth   The raw bit depth, in bits.
 211 * @return                      The error code.
 212 *
 213 * Allocate a CSS frame structure. The memory for the frame data will be
 214 * allocated in the CSS address space.
 215 */
 216int
 217ia_css_frame_allocate(struct ia_css_frame **frame,
 218                      unsigned int width,
 219                      unsigned int height,
 220                      enum ia_css_frame_format format,
 221                      unsigned int stride,
 222                      unsigned int raw_bit_depth);
 223
 224/* @brief Allocate a CSS frame structure using a frame info structure.
 225 *
 226 * @param       frame   The allocated frame.
 227 * @param[in]   info    The frame info structure.
 228 * @return              The error code.
 229 *
 230 * Allocate a frame using the resolution and format from a frame info struct.
 231 * This is a convenience function, implemented on top of
 232 * ia_css_frame_allocate().
 233 */
 234int
 235ia_css_frame_allocate_from_info(struct ia_css_frame **frame,
 236                                const struct ia_css_frame_info *info);
 237/* @brief Free a CSS frame structure.
 238 *
 239 * @param[in]   frame   Pointer to the frame.
 240 * @return      None
 241 *
 242 * Free a CSS frame structure. This will free both the frame structure
 243 * and the pixel data pointer contained within the frame structure.
 244 */
 245void
 246ia_css_frame_free(struct ia_css_frame *frame);
 247
 248/* @brief Allocate a contiguous CSS frame structure
 249 *
 250 * @param       frame           The allocated frame.
 251 * @param       width           The width (in pixels) of the frame.
 252 * @param       height          The height (in lines) of the frame.
 253 * @param       format          The frame format.
 254 * @param       stride          The padded stride, in pixels.
 255 * @param       raw_bit_depth   The raw bit depth, in bits.
 256 * @return                      The error code.
 257 *
 258 * Contiguous frame allocation, only for FPGA display driver which needs
 259 * physically contiguous memory.
 260 * Deprecated.
 261 */
 262int
 263ia_css_frame_allocate_contiguous(struct ia_css_frame **frame,
 264                                 unsigned int width,
 265                                 unsigned int height,
 266                                 enum ia_css_frame_format format,
 267                                 unsigned int stride,
 268                                 unsigned int raw_bit_depth);
 269
 270/* @brief Allocate a contiguous CSS frame from a frame info structure.
 271 *
 272 * @param       frame   The allocated frame.
 273 * @param[in]   info    The frame info structure.
 274 * @return              The error code.
 275 *
 276 * Allocate a frame using the resolution and format from a frame info struct.
 277 * This is a convenience function, implemented on top of
 278 * ia_css_frame_allocate_contiguous().
 279 * Only for FPGA display driver which needs physically contiguous memory.
 280 * Deprecated.
 281 */
 282int
 283ia_css_frame_allocate_contiguous_from_info(struct ia_css_frame **frame,
 284        const struct ia_css_frame_info *info);
 285
 286/* @brief Allocate a CSS frame structure using a frame info structure.
 287 *
 288 * @param       frame   The allocated frame.
 289 * @param[in]   info    The frame info structure.
 290 * @return              The error code.
 291 *
 292 * Allocate an empty CSS frame with no data buffer using the parameters
 293 * in the frame info.
 294 */
 295int
 296ia_css_frame_create_from_info(struct ia_css_frame **frame,
 297                              const struct ia_css_frame_info *info);
 298
 299/* @brief Set a mapped data buffer to a CSS frame
 300 *
 301 * @param[in]   frame       Valid CSS frame pointer
 302 * @param[in]   mapped_data  Mapped data buffer to be assigned to the CSS frame
 303 * @param[in]   data_size_bytes  Size of the mapped_data in bytes
 304 * @return      The error code.
 305 *
 306 * Sets a mapped data buffer to this frame. This function can be called multiple
 307 * times with different buffers or NULL to reset the data pointer. This API
 308 * would not try free the mapped_data and its the callers responsiblity to
 309 * free the mapped_data buffer. However if ia_css_frame_free() is called and
 310 * the frame had a valid data buffer, it would be freed along with the frame.
 311 */
 312int
 313ia_css_frame_set_data(struct ia_css_frame *frame,
 314                      const ia_css_ptr   mapped_data,
 315                      size_t data_size_bytes);
 316
 317/* @brief Map an existing frame data pointer to a CSS frame.
 318 *
 319 * @param       frame           Pointer to the frame to be initialized
 320 * @param[in]   info            The frame info.
 321 * @param[in]   data            Pointer to the allocated frame data.
 322 * @param[in]   attribute       Attributes to be passed to mmgr_mmap.
 323 * @param[in]   context         Pointer to the a context to be passed to mmgr_mmap.
 324 * @return                      The allocated frame structure.
 325 *
 326 * This function maps a pre-allocated pointer into a CSS frame. This can be
 327 * used when an upper software layer is responsible for allocating the frame
 328 * data and it wants to share that frame pointer with the CSS code.
 329 * This function will fill the CSS frame structure just like
 330 * ia_css_frame_allocate() does, but instead of allocating the memory, it will
 331 * map the pre-allocated memory into the CSS address space.
 332 */
 333int
 334ia_css_frame_map(struct ia_css_frame **frame,
 335                 const struct ia_css_frame_info *info,
 336                 const void __user *data,
 337                 u16 attribute,
 338                 unsigned int pgnr);
 339
 340/* @brief Unmap a CSS frame structure.
 341 *
 342 * @param[in]   frame   Pointer to the CSS frame.
 343 * @return      None
 344 *
 345 * This function unmaps the frame data pointer within a CSS frame and
 346 * then frees the CSS frame structure. Use this for frame pointers created
 347 * using ia_css_frame_map().
 348 */
 349void
 350ia_css_frame_unmap(struct ia_css_frame *frame);
 351
 352#endif /* __IA_CSS_FRAME_PUBLIC_H */
 353