xref: /linux/drivers/media/platform/renesas/vsp1/vsp1_pipe.h (revision 9557b4376d02088a33e5f4116bcc324d35a3b64c)
1 /* SPDX-License-Identifier: GPL-2.0+ */
2 /*
3  * vsp1_pipe.h  --  R-Car VSP1 Pipeline
4  *
5  * Copyright (C) 2013-2015 Renesas Electronics Corporation
6  *
7  * Contact: Laurent Pinchart (laurent.pinchart@ideasonboard.com)
8  */
9 #ifndef __VSP1_PIPE_H__
10 #define __VSP1_PIPE_H__
11 
12 #include <linux/dynamic_debug.h>
13 #include <linux/kref.h>
14 #include <linux/list.h>
15 #include <linux/spinlock.h>
16 #include <linux/wait.h>
17 
18 #include <media/media-entity.h>
19 
20 struct vsp1_dl_list;
21 struct vsp1_rwpf;
22 
23 /*
24  * struct vsp1_format_info - VSP1 video format description
25  * @fourcc: V4L2 pixel format FCC identifier
26  * @mbus: media bus format code
27  * @hwfmt: VSP1 hardware format
28  * @swap: swap register control
29  * @planes: number of planes
30  * @bpp: bits per pixel
31  * @swap_yc: the Y and C components are swapped (Y comes before C)
32  * @swap_uv: the U and V components are swapped (V comes before U)
33  * @hsub: horizontal subsampling factor
34  * @vsub: vertical subsampling factor
35  * @alpha: has an alpha channel
36  */
37 struct vsp1_format_info {
38 	u32 fourcc;
39 	unsigned int mbus;
40 	unsigned int hwfmt;
41 	unsigned int swap;
42 	unsigned int planes;
43 	unsigned int bpp[3];
44 	bool swap_yc;
45 	bool swap_uv;
46 	unsigned int hsub;
47 	unsigned int vsub;
48 	bool alpha;
49 };
50 
51 enum vsp1_pipeline_state {
52 	VSP1_PIPELINE_STOPPED,
53 	VSP1_PIPELINE_RUNNING,
54 	VSP1_PIPELINE_STOPPING,
55 };
56 
57 /*
58  * struct vsp1_partition - A description of a slice for the partition algorithm
59  * @rpf: The RPF partition window configuration
60  * @uds_sink: The UDS input partition window configuration
61  * @uds_source: The UDS output partition window configuration
62  * @sru: The SRU partition window configuration
63  * @wpf: The WPF partition window configuration
64  */
65 struct vsp1_partition {
66 	struct v4l2_rect rpf[VSP1_MAX_RPF];
67 	struct v4l2_rect uds_sink;
68 	struct v4l2_rect uds_source;
69 	struct v4l2_rect sru;
70 	struct v4l2_rect wpf;
71 };
72 
73 /*
74  * struct vsp1_pipeline - A VSP1 hardware pipeline
75  * @pipe: the media pipeline
76  * @irqlock: protects the pipeline state
77  * @state: current state
78  * @wq: wait queue to wait for state change completion
79  * @frame_end: frame end interrupt handler
80  * @lock: protects the pipeline use count and stream count
81  * @kref: pipeline reference count
82  * @stream_count: number of streaming video nodes
83  * @buffers_ready: bitmask of RPFs and WPFs with at least one buffer available
84  * @sequence: frame sequence number
85  * @num_inputs: number of RPFs
86  * @inputs: array of RPFs in the pipeline (indexed by RPF index)
87  * @output: WPF at the output of the pipeline
88  * @brx: BRx entity, if present
89  * @hgo: HGO entity, if present
90  * @hgt: HGT entity, if present
91  * @lif: LIF entity, if present
92  * @uds: UDS entity, if present
93  * @uds_input: entity at the input of the UDS, if the UDS is present
94  * @entities: list of entities in the pipeline
95  * @stream_config: cached stream configuration for video pipelines
96  * @configured: when false the @stream_config shall be written to the hardware
97  * @interlaced: True when the pipeline is configured in interlaced mode
98  * @partitions: The number of partitions used to process one frame
99  * @part_table: The pre-calculated partitions used by the pipeline
100  */
101 struct vsp1_pipeline {
102 	struct media_pipeline pipe;
103 
104 	spinlock_t irqlock;
105 	enum vsp1_pipeline_state state;
106 	wait_queue_head_t wq;
107 
108 	void (*frame_end)(struct vsp1_pipeline *pipe, unsigned int completion);
109 
110 	struct mutex lock;
111 	struct kref kref;
112 	unsigned int stream_count;
113 	unsigned int buffers_ready;
114 	unsigned int sequence;
115 
116 	unsigned int num_inputs;
117 	struct vsp1_rwpf *inputs[VSP1_MAX_RPF];
118 	struct vsp1_rwpf *output;
119 	struct vsp1_entity *brx;
120 	struct vsp1_entity *hgo;
121 	struct vsp1_entity *hgt;
122 	struct vsp1_entity *lif;
123 	struct vsp1_entity *uds;
124 	struct vsp1_entity *uds_input;
125 
126 	/*
127 	 * The order of this list must be identical to the order of the entities
128 	 * in the pipeline, as it is assumed by the partition algorithm that we
129 	 * can walk this list in sequence.
130 	 */
131 	struct list_head entities;
132 
133 	struct vsp1_dl_body *stream_config;
134 	bool configured;
135 	bool interlaced;
136 
137 	unsigned int partitions;
138 	struct vsp1_partition *part_table;
139 
140 	u32 underrun_count;
141 };
142 
143 void vsp1_pipeline_reset(struct vsp1_pipeline *pipe);
144 void vsp1_pipeline_init(struct vsp1_pipeline *pipe);
145 
146 void __vsp1_pipeline_dump(struct _ddebug *, struct vsp1_pipeline *pipe,
147 			  const char *msg);
148 
149 #if defined(CONFIG_DYNAMIC_DEBUG) || \
150 	(defined(CONFIG_DYNAMIC_DEBUG_CORE) && defined(DYNAMIC_DEBUG_MODULE))
151 #define vsp1_pipeline_dump(pipe, msg)			\
152 	_dynamic_func_call("vsp1_pipeline_dump()", __vsp1_pipeline_dump, pipe, msg)
153 #elif defined(DEBUG)
154 #define vsp1_pipeline_dump(pipe, msg)			\
155 	__vsp1_pipeline_dump(NULL, pipe, msg)
156 #else
157 #define vsp1_pipeline_dump(pipe, msg)			\
158 ({							\
159 	if (0)						\
160 		__vsp1_pipeline_dump(NULL, pipe, msg);	\
161 })
162 #endif
163 
164 void vsp1_pipeline_run(struct vsp1_pipeline *pipe);
165 bool vsp1_pipeline_stopped(struct vsp1_pipeline *pipe);
166 int vsp1_pipeline_stop(struct vsp1_pipeline *pipe);
167 bool vsp1_pipeline_ready(struct vsp1_pipeline *pipe);
168 
169 void vsp1_pipeline_frame_end(struct vsp1_pipeline *pipe);
170 
171 void vsp1_pipeline_propagate_alpha(struct vsp1_pipeline *pipe,
172 				   struct vsp1_dl_body *dlb,
173 				   unsigned int alpha);
174 
175 void vsp1_pipeline_calculate_partition(struct vsp1_pipeline *pipe,
176 				       struct vsp1_partition *partition,
177 				       unsigned int div_size,
178 				       unsigned int index);
179 
180 const struct vsp1_format_info *vsp1_get_format_info(struct vsp1_device *vsp1,
181 						    u32 fourcc);
182 
183 #endif /* __VSP1_PIPE_H__ */
184