linux/drivers/staging/media/atomisp/pci/sh_css_internal.h

/* SPDX-License-Identifier: GPL-2.0 */
/*
 * Support for Intel Camera Imaging ISP subsystem.
 * Copyright (c) 2015, Intel Corporation.
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms and conditions of the GNU General Public License,
 * version 2, as published by the Free Software Foundation.
 *
 * This program is distributed in the hope it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 * more details.
 */

#ifndef _SH_CSS_INTERNAL_H_
#define _SH_CSS_INTERNAL_H_

#include <linux/build_bug.h>
#include <linux/stdarg.h>

#include <system_global.h>
#include <math_support.h>
#include <type_support.h>
#include <platform_support.h>

#include "input_formatter.h"
#include "input_system.h"

#include "ia_css_types.h"
#include "ia_css_acc_types.h"
#include "ia_css_buffer.h"

#include "ia_css_binary.h"
#include "sh_css_firmware.h" /* not needed/desired on SP/ISP */
#include "sh_css_legacy.h"
#include "sh_css_defs.h"
#include "sh_css_uds.h"
#include "dma.h"	/* N_DMA_CHANNEL_ID */
#include "ia_css_circbuf_comm.h" /* Circular buffer */
#include "ia_css_frame_comm.h"
#include "ia_css_3a.h"
#include "ia_css_dvs.h"
#include "ia_css_metadata.h"
#include "runtime/bufq/interface/ia_css_bufq.h"
#include "ia_css_timer.h"

/* TODO: Move to a more suitable place when sp pipeline design is done. */
#define IA_CSS_NUM_CB_SEM_READ_RESOURCE
#define IA_CSS_NUM_CB_SEM_WRITE_RESOURCE
#define IA_CSS_NUM_CBS
#define IA_CSS_CB_MAX_ELEMS

/* Use case specific. index limited to IA_CSS_NUM_CB_SEM_READ_RESOURCE or
 * IA_CSS_NUM_CB_SEM_WRITE_RESOURCE for read and write respectively.
 * TODO: Enforce the limitation above.
*/
#define IA_CSS_COPYSINK_SEM_INDEX
#define IA_CSS_TAGGER_SEM_INDEX

/* Force generation of output event. Used by acceleration pipe. */
#define IA_CSS_POST_OUT_EVENT_FORCE

#define SH_CSS_MAX_BINARY_NAME

#define SP_DEBUG_NONE
#define SP_DEBUG_DUMP
#define SP_DEBUG_COPY
#define SP_DEBUG_TRACE
#define SP_DEBUG_MINIMAL

#define SP_DEBUG
#define SP_DEBUG_MINIMAL_OVERWRITE

#define SH_CSS_TNR_BIT_DEPTH
#define SH_CSS_REF_BIT_DEPTH

/* keep next up to date with the definition for MAX_CB_ELEMS_FOR_TAGGER in tagger.sp.c */
#define NUM_CONTINUOUS_FRAMES
#define NUM_MIPI_FRAMES_PER_STREAM

#define NUM_ONLINE_INIT_CONTINUOUS_FRAMES

#define NR_OF_PIPELINES

#define SH_CSS_MAX_IF_CONFIGS
#define SH_CSS_IF_CONFIG_NOT_NEEDED

#define SH_CSS_MAX_SP_THREADS

/**
 * The C99 standard does not specify the exact object representation of structs;
 * the representation is compiler dependent.
 *
 * The structs that are communicated between host and SP/ISP should have the
 * exact same object representation. The compiler that is used to compile the
 * firmware is hivecc.
 *
 * To check if a different compiler, used to compile a host application, uses
 * another object representation, macros are defined specifying the size of
 * the structs as expected by the firmware.
 *
 * A host application shall verify that a sizeof( ) of the struct is equal to
 * the SIZE_OF_XXX macro of the corresponding struct. If they are not
 * equal, functionality will break.
 */
#define CALC_ALIGNMENT_MEMBER(x, y)
#define SIZE_OF_HRT_VADDRESS

/* Number of SP's */
#define NUM_OF_SPS

#define NUM_OF_BLS

/* Enum for order of Binaries */
enum sh_css_order_binaries {};

/*
* JB: keep next enum in sync with thread id's
* and pipe id's
*/
enum sh_css_pipe_config_override {};

enum host2sp_commands {};

/* Enumeration used to indicate the events that are produced by
 *  the SP and consumed by the Host.
 *
 * !!!IMPORTANT!!! KEEP THE FOLLOWING IN SYNC:
 * 1) "enum ia_css_event_type"					(ia_css_event_public.h)
 * 2) "enum sh_css_sp_event_type"				(sh_css_internal.h)
 * 3) "enum ia_css_event_type event_id_2_event_mask"		(event_handler.sp.c)
 * 4) "enum ia_css_event_type convert_event_sp_to_host_domain"	(sh_css.c)
 */
enum sh_css_sp_event_type {};

/* xmem address map allocation per pipeline, css pointers */
/* Note that the struct below should only consist of ia_css_ptr-es
   Otherwise this will cause a fail in the function ref_sh_css_ddr_address_map
 */
struct sh_css_ddr_address_map {};

#define SIZE_OF_SH_CSS_DDR_ADDRESS_MAP_STRUCT

static_assert();

/* xmem address map allocation per pipeline */
struct sh_css_ddr_address_map_size {};

struct sh_css_ddr_address_map_compound {};

struct ia_css_isp_parameter_set_info {};

/* this struct contains all arguments that can be passed to
   a binary. It depends on the binary which ones are used. */
struct sh_css_binary_args {};

#if SP_DEBUG == SP_DEBUG_DUMP

#define SH_CSS_NUM_SP_DEBUG

struct sh_css_sp_debug_state {
	unsigned int error;
	unsigned int debug[SH_CSS_NUM_SP_DEBUG];
};

#elif SP_DEBUG == SP_DEBUG_COPY

#define SH_CSS_SP_DBG_TRACE_DEPTH

struct sh_css_sp_debug_trace {
	u16 frame;
	u16 line;
	u16 pixel_distance;
	u16 mipi_used_dword;
	u16 sp_index;
};

struct sh_css_sp_debug_state {
	u16 if_start_line;
	u16 if_start_column;
	u16 if_cropped_height;
	u16 if_cropped_width;
	unsigned int index;
	struct sh_css_sp_debug_trace
		trace[SH_CSS_SP_DBG_TRACE_DEPTH];
};

#elif SP_DEBUG == SP_DEBUG_TRACE

/* Example of just one global trace */
#define SH_CSS_SP_DBG_NR_OF_TRACES
#define SH_CSS_SP_DBG_TRACE_DEPTH

#define SH_CSS_SP_DBG_TRACE_FILE_ID_BIT_POS

struct sh_css_sp_debug_trace {
	u16 time_stamp;
	u16 location;	/* bit 15..13 = file_id, 12..0 = line nr. */
	u32 data;
};

struct sh_css_sp_debug_state {
	struct sh_css_sp_debug_trace
		trace[SH_CSS_SP_DBG_NR_OF_TRACES][SH_CSS_SP_DBG_TRACE_DEPTH];
	u16 index_last[SH_CSS_SP_DBG_NR_OF_TRACES];
	u8 index[SH_CSS_SP_DBG_NR_OF_TRACES];
};

#elif SP_DEBUG == SP_DEBUG_MINIMAL

#define SH_CSS_NUM_SP_DEBUG

struct sh_css_sp_debug_state {
	unsigned int error;
	unsigned int debug[SH_CSS_NUM_SP_DEBUG];
};

#endif

struct sh_css_sp_debug_command {};

/* SP input formatter configuration.*/
struct sh_css_sp_input_formatter_set {};

#define IA_CSS_MIPI_SIZE_CHECK_MAX_NOF_ENTRIES_PER_PORT

/* SP configuration information */
struct sh_css_sp_config {};

enum sh_css_stage_type {};

#define SH_CSS_NUM_STAGE_TYPES

#define SH_CSS_PIPE_CONFIG_SAMPLE_PARAMS
#define SH_CSS_PIPE_CONFIG_SAMPLE_PARAMS_MASK

struct sh_css_sp_pipeline_terminal {};

struct sh_css_sp_pipeline_io {};

/* This struct tracks how many streams are registered per CSI port.
 * This is used to track which streams have already been configured.
 * Only when all streams are configured, the CSI RX is started for that port.
 */
struct sh_css_sp_pipeline_io_status {};

enum sh_css_port_dir {};

enum sh_css_port_type {};

/* Pipe inout settings: output port on 7-4bits, input port on 3-0bits */
#define SH_CSS_PORT_FLD_WIDTH_IN_BITS
#define SH_CSS_PORT_TYPE_BIT_FLD(pt)
#define SH_CSS_PORT_FLD(pd)
#define SH_CSS_PIPE_PORT_CONFIG_ON(p, pd, pt)
#define SH_CSS_PIPE_PORT_CONFIG_OFF(p, pd, pt)
#define SH_CSS_PIPE_PORT_CONFIG_SET(p, pd, pt, val)
#define SH_CSS_PIPE_PORT_CONFIG_GET(p, pd, pt)
#define SH_CSS_PIPE_PORT_CONFIG_IS_CONTINUOUS(p)

#define IA_CSS_ACQUIRE_ISP_POS

/* Flags for metadata processing */
#define SH_CSS_METADATA_ENABLED
#define SH_CSS_METADATA_PROCESSED
#define SH_CSS_METADATA_OFFLINE_MODE
#define SH_CSS_METADATA_WAIT_INPUT

/* @brief Free an array of metadata buffers.
 *
 * @param[in]	num_bufs	Number of metadata buffers to be freed.
 * @param[in]	bufs		Pointer of array of metadata buffers.
 *
 * This function frees an array of metadata buffers.
 */
void
ia_css_metadata_free_multiple(unsigned int num_bufs,
			      struct ia_css_metadata **bufs);

/* Macro for handling pipe_qos_config */
#define QOS_INVALID

/* Information for a pipeline */
struct sh_css_sp_pipeline {};

/*
 * The first frames (with comment Dynamic) can be dynamic or static
 * The other frames (ref_in and below) can only be static
 * Static means that the data address will not change during the life time
 * of the associated pipe. Dynamic means that the data address can
 * change with every (frame) iteration of the associated pipe
 *
 * s3a and dis are now also dynamic but (still) handled separately
 */
#define SH_CSS_NUM_DYNAMIC_FRAME_IDS

struct ia_css_frames_sp {};

/* Information for a single pipeline stage for an ISP */
struct sh_css_isp_stage {};

/* Information for a single pipeline stage */
struct sh_css_sp_stage {};

/*
 * Time: 2012-07-19, 17:40.
 * Note: Add a new data member "debug" in "sh_css_sp_group". This
 * data member is used to pass the debugging command from the
 * Host to the SP.
 *
 * Time: Before 2012-07-19.
 * Note:
 * Group all host initialized SP variables into this struct.
 * This is initialized every stage through dma.
 * The stage part itself is transferred through sh_css_sp_stage.
*/
struct sh_css_sp_group {};

/* Data in SP dmem that is set from the host every stage. */
struct sh_css_sp_per_frame_data {};

#define SH_CSS_NUM_SDW_IRQS

/* Output data from SP to css */
struct sh_css_sp_output {};

/**
 * @brief Data structure for the circular buffer.
 * The circular buffer is empty if "start == end". The
 * circular buffer is full if "(end + 1) % size == start".
 */
/* Variable Sized Buffer Queue Elements */

#define IA_CSS_NUM_ELEMS_HOST2SP_BUFFER_QUEUE
#define IA_CSS_NUM_ELEMS_HOST2SP_PARAM_QUEUE
#define IA_CSS_NUM_ELEMS_HOST2SP_TAG_CMD_QUEUE

/* sp-to-host queue is expected to be emptied in ISR since
 * it is used instead of HW interrupts (due to HW design issue).
 * We need one queue element per CSI port. */
#define IA_CSS_NUM_ELEMS_SP2HOST_ISYS_EVENT_QUEUE
/* The host-to-sp queue needs to allow for some delay
 * in the emptying of this queue in the SP since there is no
 * separate SP thread for this. */
#define IA_CSS_NUM_ELEMS_HOST2SP_ISYS_EVENT_QUEUE

#define IA_CSS_NUM_ELEMS_HOST2SP_PSYS_EVENT_QUEUE
#define IA_CSS_NUM_ELEMS_SP2HOST_BUFFER_QUEUE
#define IA_CSS_NUM_ELEMS_SP2HOST_PSYS_EVENT_QUEUE

struct sh_css_hmm_buffer {};

#define SIZE_OF_FRAME_STRUCT

#define SIZE_OF_PAYLOAD_UNION

/* Do not use sizeof(uint64_t) since that does not exist of SP */
#define SIZE_OF_SH_CSS_HMM_BUFFER_STRUCT

static_assert();

enum sh_css_queue_type {};

struct sh_css_event_irq_mask {};

#define SIZE_OF_SH_CSS_EVENT_IRQ_MASK_STRUCT

static_assert();

struct host_sp_communication {};

#define SIZE_OF_HOST_SP_COMMUNICATION_STRUCT

static_assert();

struct host_sp_queues {};

#define SIZE_OF_QUEUES_ELEMS

#define IA_CSS_NUM_CIRCBUF_DESCS

#define SIZE_OF_QUEUES_DESC

#define SIZE_OF_HOST_SP_QUEUES_STRUCT

static_assert();

extern int  __printf(1, 0) (*sh_css_printf)(const char *fmt, va_list args);

static inline void  __printf(1, 2) sh_css_print(const char *fmt, ...)
{}

static inline void  __printf(1, 0) sh_css_vprint(const char *fmt, va_list args)
{}

/* The following #if is there because this header file is also included
   by SP and ISP code but they do not need this data and HIVECC has alignment
   issue with the firmware struct/union's.
   More permanent solution will be to refactor this include.
*/
ia_css_ptr sh_css_params_ddr_address_map(void);

int
sh_css_params_init(void);

void
sh_css_params_uninit(void);

void
sh_css_binary_args_reset(struct sh_css_binary_args *args);

/* Check two frames for equality (format, resolution, bits per element) */
bool
sh_css_frame_equal_types(const struct ia_css_frame *frame_a,
			 const struct ia_css_frame *frame_b);

bool
sh_css_frame_info_equal_resolution(const struct ia_css_frame_info *info_a,
				   const struct ia_css_frame_info *info_b);

void
sh_css_capture_enable_bayer_downscaling(bool enable);

void
sh_css_binary_print(const struct ia_css_binary *binary);

/* aligned argument of sh_css_frame_info_set_width can be used for an extra alignment requirement.
  When 0, no extra alignment is done. */
void
sh_css_frame_info_set_width(struct ia_css_frame_info *info,
			    unsigned int width,
			    unsigned int aligned);


unsigned int
sh_css_get_mipi_sizes_for_check(const unsigned int port,
				const unsigned int idx);


ia_css_ptr
sh_css_store_sp_group_to_ddr(void);

ia_css_ptr
sh_css_store_sp_stage_to_ddr(unsigned int pipe, unsigned int stage);

ia_css_ptr
sh_css_store_isp_stage_to_ddr(unsigned int pipe, unsigned int stage);

void
sh_css_update_uds_and_crop_info(
    const struct ia_css_binary_info *info,
    const struct ia_css_frame_info *in_frame_info,
    const struct ia_css_frame_info *out_frame_info,
    const struct ia_css_resolution *dvs_env,
    const struct ia_css_dz_config *zoom,
    const struct ia_css_vector *motion_vector,
    struct sh_css_uds_info *uds,		/* out */
    struct sh_css_crop_pos *sp_out_crop_pos,	/* out */

    bool enable_zoom
);

void
sh_css_invalidate_shading_tables(struct ia_css_stream *stream);

struct ia_css_pipeline *
ia_css_pipe_get_pipeline(const struct ia_css_pipe *pipe);

unsigned int
ia_css_pipe_get_pipe_num(const struct ia_css_pipe *pipe);

unsigned int
ia_css_pipe_get_isp_pipe_version(const struct ia_css_pipe *pipe);

bool
sh_css_continuous_is_enabled(uint8_t pipe_num);

struct ia_css_pipe *
find_pipe_by_num(uint32_t pipe_num);

void
ia_css_get_crop_offsets(
    struct ia_css_pipe *pipe,
    struct ia_css_frame_info *in_frame);

#endif /* _SH_CSS_INTERNAL_H_ */