1 /* 2 * drivers/amlogic/media/frame_provider/decoder/utils/vdec.h 3 * 4 * Copyright (C) 2016 Amlogic, Inc. All rights reserved. 5 * 6 * This program is free software; you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License as published by 8 * the Free Software Foundation; either version 2 of the License, or 9 * (at your option) any later version. 10 * 11 * This program is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 14 * more details. 15 * 16 */ 17 18 #ifndef VDEC_H 19 #define VDEC_H 20 #include <linux/amlogic/media/utils/amports_config.h> 21 #include <linux/interrupt.h> 22 #include <linux/platform_device.h> 23 #include <linux/list.h> 24 #include <linux/completion.h> 25 #include <linux/irqreturn.h> 26 27 #include <linux/amlogic/media/utils/amstream.h> 28 #include <linux/amlogic/media/vfm/vframe.h> 29 #include <linux/amlogic/media/vfm/vframe_provider.h> 30 #include <linux/amlogic/media/vfm/vframe_receiver.h> 31 #define KERNEL_ATRACE_TAG KERNEL_ATRACE_TAG_VDEC 32 #include <linux/amlogic/meson_atrace.h> 33 /*#define CONFIG_AM_VDEC_DV*/ 34 #include "../../../stream_input/amports/streambuf.h" 35 #include "../../../stream_input/amports/stream_buffer_base.h" 36 37 #include "vdec_input.h" 38 #include "frame_check.h" 39 40 s32 vdec_dev_register(void); 41 s32 vdec_dev_unregister(void); 42 43 int vdec_source_changed(int format, int width, int height, int fps); 44 int vdec2_source_changed(int format, int width, int height, int fps); 45 int hevc_source_changed(int format, int width, int height, int fps); 46 struct device *get_vdec_device(void); 47 int vdec_module_init(void); 48 void vdec_module_exit(void); 49 50 #define MAX_INSTANCE_MUN 9 51 52 //#define VDEC_DEBUG_SUPPORT 53 54 #define DEC_FLAG_HEVC_WORKAROUND 0x01 55 56 #define VDEC_FIFO_ALIGN 8 57 58 enum vdec_type_e { 59 VDEC_1 = 0, 60 VDEC_HCODEC, 61 VDEC_2, 62 VDEC_HEVC, 63 VDEC_HEVCB, 64 VDEC_MAX 65 }; 66 67 #define CORE_MASK_VDEC_1 (1 << VDEC_1) 68 #define CORE_MASK_HCODEC (1 << VDEC_HCODEC) 69 #define CORE_MASK_VDEC_2 (1 << VDEC_2) 70 #define CORE_MASK_HEVC (1 << VDEC_HEVC) 71 #define CORE_MASK_HEVC_FRONT (1 << VDEC_HEVC) 72 #define CORE_MASK_HEVC_BACK (1 << VDEC_HEVCB) 73 #define CORE_MASK_COMBINE (1UL << 31) 74 75 extern void vdec2_power_mode(int level); 76 extern void vdec_poweron(enum vdec_type_e core); 77 extern void vdec_poweroff(enum vdec_type_e core); 78 extern bool vdec_on(enum vdec_type_e core); 79 extern void vdec_power_reset(void); 80 81 /*irq num as same as .dts*/ 82 83 /* 84 * interrupts = <0 3 1 85 * 0 23 1 86 * 0 32 1 87 * 0 43 1 88 * 0 44 1 89 * 0 45 1>; 90 * interrupt-names = "vsync", 91 * "demux", 92 * "parser", 93 * "mailbox_0", 94 * "mailbox_1", 95 * "mailbox_2"; 96 */ 97 enum vdec_irq_num { 98 VSYNC_IRQ = 0, 99 DEMUX_IRQ, 100 PARSER_IRQ, 101 VDEC_IRQ_0, 102 VDEC_IRQ_1, 103 VDEC_IRQ_2, 104 VDEC_IRQ_HEVC_BACK, 105 VDEC_IRQ_MAX, 106 }; 107 108 enum vdec_fr_hint_state { 109 VDEC_NO_NEED_HINT = 0, 110 VDEC_NEED_HINT, 111 VDEC_HINTED, 112 }; 113 extern s32 vdec_request_threaded_irq(enum vdec_irq_num num, 114 irq_handler_t handler, 115 irq_handler_t thread_fn, 116 unsigned long irqflags, 117 const char *devname, void *dev); 118 extern s32 vdec_request_irq(enum vdec_irq_num num, irq_handler_t handler, 119 const char *devname, void *dev); 120 extern void vdec_free_irq(enum vdec_irq_num num, void *dev); 121 122 extern void dma_contiguous_early_fixup(phys_addr_t base, unsigned long size); 123 unsigned int get_vdec_clk_config_settings(void); 124 void update_vdec_clk_config_settings(unsigned int config); 125 //unsigned int get_mmu_mode(void);//DEBUG_TMP 126 //extern void vdec_fill_frame_info(struct vframe_qos_s *vframe_qos, int debug); 127 extern void vdec_fill_vdec_frame(struct vdec_s *vdec, 128 struct vframe_qos_s *vframe_qos, 129 struct vdec_info *vinfo, 130 struct vframe_s *vf, u32 hw_dec_time); 131 extern void vdec_set_vframe_comm(struct vdec_s *vdec, char *n); 132 133 134 struct vdec_s; 135 enum vformat_t; 136 137 /* stream based with single instance decoder driver */ 138 #define VDEC_TYPE_SINGLE 0 139 140 /* stream based with multi-instance decoder with HW resouce sharing */ 141 #define VDEC_TYPE_STREAM_PARSER 1 142 143 /* frame based with multi-instance decoder, input block list based */ 144 #define VDEC_TYPE_FRAME_BLOCK 2 145 146 /* frame based with multi-instance decoder, single circular input block */ 147 #define VDEC_TYPE_FRAME_CIRCULAR 3 148 149 /* decoder status: uninitialized */ 150 #define VDEC_STATUS_UNINITIALIZED 0 151 152 /* decoder status: before the decoder can start consuming data */ 153 #define VDEC_STATUS_DISCONNECTED 1 154 155 /* decoder status: decoder should become disconnected once it's not active */ 156 #define VDEC_STATUS_CONNECTED 2 157 158 /* decoder status: decoder owns HW resource and is running */ 159 #define VDEC_STATUS_ACTIVE 3 160 161 #define VDEC_PROVIDER_NAME_SIZE 16 162 #define VDEC_RECEIVER_NAME_SIZE 16 163 #define VDEC_MAP_NAME_SIZE 90 164 165 #define VDEC_FLAG_OTHER_INPUT_CONTEXT 0x0 166 #define VDEC_FLAG_SELF_INPUT_CONTEXT 0x01 167 168 #define VDEC_NEED_MORE_DATA_RUN 0x01 169 #define VDEC_NEED_MORE_DATA_DIRTY 0x02 170 #define VDEC_NEED_MORE_DATA 0x04 171 172 struct vdec_s { 173 u32 magic; 174 struct list_head list; 175 unsigned long core_mask; 176 unsigned long active_mask; 177 unsigned long sched_mask; 178 int id; 179 180 struct vdec_s *master; 181 struct vdec_s *slave; 182 struct stream_port_s *port; 183 struct stream_buf_s vbuf; 184 int status; 185 int next_status; 186 int type; 187 int port_flag; 188 int format; 189 u32 pts; 190 u64 pts64; 191 bool pts_valid; 192 u64 timestamp; 193 bool timestamp_valid; 194 int flag; 195 int sched; 196 int need_more_data; 197 u32 canvas_mode; 198 199 struct completion inactive_done; 200 201 /* config (temp) */ 202 unsigned long mem_start; 203 unsigned long mem_end; 204 205 void *mm_blk_handle; 206 207 struct device *cma_dev; 208 struct platform_device *dev; 209 struct dec_sysinfo sys_info_store; 210 struct dec_sysinfo *sys_info; 211 212 /* input */ 213 struct vdec_input_s input; 214 215 /*frame check*/ 216 struct pic_check_mgr_t vfc; 217 218 /* mc cache */ 219 u32 mc[4096 * 4]; 220 bool mc_loaded; 221 u32 mc_type; 222 /* frame provider/receiver interface */ 223 char vf_provider_name[VDEC_PROVIDER_NAME_SIZE]; 224 struct vframe_provider_s vframe_provider; 225 char *vf_receiver_name; 226 char vfm_map_id[VDEC_MAP_NAME_SIZE]; 227 char vfm_map_chain[VDEC_MAP_NAME_SIZE]; 228 int vf_receiver_inst; 229 enum FRAME_BASE_VIDEO_PATH frame_base_video_path; 230 enum vdec_fr_hint_state fr_hint_state; 231 bool use_vfm_path; 232 char config[PAGE_SIZE]; 233 int config_len; 234 bool is_reset; 235 bool dolby_meta_with_el; 236 237 /* canvas */ 238 int (*get_canvas)(unsigned int index, unsigned int base); 239 int (*get_canvas_ex)(int type, int id); 240 void (*free_canvas_ex)(int index, int id); 241 242 int (*dec_status)(struct vdec_s *vdec, struct vdec_info *vstatus); 243 int (*set_trickmode)(struct vdec_s *vdec, unsigned long trickmode); 244 int (*set_isreset)(struct vdec_s *vdec, int isreset); 245 void (*vdec_fps_detec)(int id); 246 247 unsigned long (*run_ready)(struct vdec_s *vdec, unsigned long mask); 248 void (*run)(struct vdec_s *vdec, unsigned long mask, 249 void (*callback)(struct vdec_s *, void *), void *); 250 void (*reset)(struct vdec_s *vdec); 251 void (*dump_state)(struct vdec_s *vdec); 252 irqreturn_t (*irq_handler)(struct vdec_s *vdec, int irq); 253 irqreturn_t (*threaded_irq_handler)(struct vdec_s *vdec, int irq); 254 255 int (*user_data_read)(struct vdec_s *vdec, 256 struct userdata_param_t *puserdata_para); 257 void (*reset_userdata_fifo)(struct vdec_s *vdec, int bInit); 258 void (*wakeup_userdata_poll)(struct vdec_s *vdec); 259 /* private */ 260 void *private; /* decoder per instance specific data */ 261 #ifdef VDEC_DEBUG_SUPPORT 262 u64 profile_start_clk[VDEC_MAX]; 263 u64 total_clk[VDEC_MAX]; 264 u32 check_count[VDEC_MAX]; 265 u32 not_run_ready_count[VDEC_MAX]; 266 u32 input_underrun_count[VDEC_MAX]; 267 u32 run_count[VDEC_MAX]; 268 u64 run_clk[VDEC_MAX]; 269 u64 start_run_clk[VDEC_MAX]; 270 #endif 271 atomic_t inirq_thread_flag; 272 atomic_t inirq_flag; 273 atomic_t inrelease; 274 int parallel_dec; 275 struct vdec_frames_s *mvfrm; 276 }; 277 278 /* common decoder vframe provider name to use default vfm path */ 279 #define VFM_DEC_PROVIDER_NAME "decoder" 280 #define VFM_DEC_DVBL_PROVIDER_NAME "dvbldec" 281 #define VFM_DEC_DVEL_PROVIDER_NAME "dveldec" 282 283 #define hw_to_vdec(hw) ((struct vdec_s *) \ 284 (platform_get_drvdata(hw->platform_dev))) 285 286 #define canvas_y(canvas) ((canvas) & 0xff) 287 #define canvas_u(canvas) (((canvas) >> 8) & 0xff) 288 #define canvas_v(canvas) (((canvas) >> 16) & 0xff) 289 #define canvas_y2(canvas) (((canvas) >> 16) & 0xff) 290 #define canvas_u2(canvas) (((canvas) >> 24) & 0xff) 291 292 #define vdec_frame_based(vdec) \ 293 (((vdec)->type == VDEC_TYPE_FRAME_BLOCK) || \ 294 ((vdec)->type == VDEC_TYPE_FRAME_CIRCULAR)) 295 #define vdec_stream_based(vdec) \ 296 (((vdec)->type == VDEC_TYPE_STREAM_PARSER) || \ 297 ((vdec)->type == VDEC_TYPE_SINGLE)) 298 #define vdec_single(vdec) \ 299 ((vdec)->type == VDEC_TYPE_SINGLE) 300 #define vdec_dual(vdec) \ 301 (((vdec)->port->type & PORT_TYPE_DUALDEC) ||\ 302 (vdec_get_debug_flags() & 0x100)) 303 #define vdec_secure(vdec) \ 304 (((vdec)->port_flag & PORT_FLAG_DRM)) 305 306 /* construct vdec strcture */ 307 extern struct vdec_s *vdec_create(struct stream_port_s *port, 308 struct vdec_s *master); 309 310 /* set video format */ 311 extern int vdec_set_format(struct vdec_s *vdec, int format); 312 313 /* set PTS */ 314 extern int vdec_set_pts(struct vdec_s *vdec, u32 pts); 315 316 extern int vdec_set_pts64(struct vdec_s *vdec, u64 pts64); 317 318 /* set vfm map when use frame base decoder */ 319 extern int vdec_set_video_path(struct vdec_s *vdec, int video_path); 320 321 /* set receive id when receive is ionvideo or amlvideo */ 322 extern int vdec_set_receive_id(struct vdec_s *vdec, int receive_id); 323 324 /* add frame data to input chain */ 325 extern int vdec_write_vframe(struct vdec_s *vdec, const char *buf, 326 size_t count); 327 328 extern int vdec_write_vframe_with_dma(struct vdec_s *vdec, 329 ulong addr, size_t count, u32 handle); 330 331 /* mark the vframe_chunk as consumed */ 332 extern void vdec_vframe_dirty(struct vdec_s *vdec, 333 struct vframe_chunk_s *chunk); 334 335 /* prepare decoder input */ 336 extern int vdec_prepare_input(struct vdec_s *vdec, struct vframe_chunk_s **p); 337 338 /* clean decoder input */ 339 extern void vdec_clean_input(struct vdec_s *vdec); 340 341 /* sync decoder input */ 342 extern int vdec_sync_input(struct vdec_s *vdec); 343 344 /* enable decoder input */ 345 extern void vdec_enable_input(struct vdec_s *vdec); 346 347 /* set decoder input prepare level */ 348 extern void vdec_set_prepare_level(struct vdec_s *vdec, int level); 349 350 /* set vdec input */ 351 extern int vdec_set_input_buffer(struct vdec_s *vdec, u32 start, u32 size); 352 353 /* check if decoder can get more input */ 354 extern bool vdec_has_more_input(struct vdec_s *vdec); 355 356 /* allocate input chain 357 * register vdec_device 358 * create output, vfm or create ionvideo output 359 * insert vdec to vdec_manager for scheduling 360 */ 361 extern int vdec_connect(struct vdec_s *vdec); 362 363 /* remove vdec from vdec_manager scheduling 364 * release input chain 365 * disconnect video output from ionvideo 366 */ 367 extern int vdec_disconnect(struct vdec_s *vdec); 368 369 /* release vdec structure */ 370 extern int vdec_destroy(struct vdec_s *vdec); 371 372 /* reset vdec */ 373 extern int vdec_reset(struct vdec_s *vdec); 374 375 extern int vdec_v4l2_reset(struct vdec_s *vdec, int flag); 376 377 extern void vdec_set_status(struct vdec_s *vdec, int status); 378 379 extern void vdec_set_next_status(struct vdec_s *vdec, int status); 380 381 extern int vdec_set_decinfo(struct vdec_s *vdec, struct dec_sysinfo *p); 382 383 extern int vdec_init(struct vdec_s *vdec, int is_4k); 384 385 extern void vdec_release(struct vdec_s *vdec); 386 387 extern int vdec_status(struct vdec_s *vdec, struct vdec_info *vstatus); 388 389 extern int vdec_set_trickmode(struct vdec_s *vdec, unsigned long trickmode); 390 391 extern int vdec_set_isreset(struct vdec_s *vdec, int isreset); 392 393 extern int vdec_set_dv_metawithel(struct vdec_s *vdec, int isdvmetawithel); 394 395 extern void vdec_set_no_powerdown(int flag); 396 397 extern int vdec_is_support_4k(void); 398 extern void vdec_set_flag(struct vdec_s *vdec, u32 flag); 399 400 extern void vdec_set_eos(struct vdec_s *vdec, bool eos); 401 402 extern void vdec_set_next_sched(struct vdec_s *vdec, struct vdec_s *next_vdec); 403 404 extern const char *vdec_status_str(struct vdec_s *vdec); 405 406 extern const char *vdec_type_str(struct vdec_s *vdec); 407 408 extern const char *vdec_device_name_str(struct vdec_s *vdec); 409 410 extern void vdec_schedule_work(struct work_struct *work); 411 412 extern void vdec_count_info(struct vdec_info *vs, unsigned int err, 413 unsigned int offset); 414 415 extern bool vdec_need_more_data(struct vdec_s *vdec); 416 417 extern void vdec_reset_core(struct vdec_s *vdec); 418 419 extern void hevc_reset_core(struct vdec_s *vdec); 420 421 extern void vdec_set_suspend_clk(int mode, int hevc); 422 423 extern unsigned long vdec_ready_to_run(struct vdec_s *vdec, unsigned long mask); 424 425 extern void vdec_prepare_run(struct vdec_s *vdec, unsigned long mask); 426 427 extern void vdec_core_request(struct vdec_s *vdec, unsigned long mask); 428 429 extern int vdec_core_release(struct vdec_s *vdec, unsigned long mask); 430 431 extern bool vdec_core_with_input(unsigned long mask); 432 433 extern void vdec_core_finish_run(struct vdec_s *vdec, unsigned long mask); 434 435 #ifdef VDEC_DEBUG_SUPPORT 436 extern void vdec_set_step_mode(void); 437 #endif 438 extern void hevc_mmu_dma_check(struct vdec_s *vdec); 439 int vdec_read_user_data(struct vdec_s *vdec, 440 struct userdata_param_t *p_userdata_param); 441 442 int vdec_wakeup_userdata_poll(struct vdec_s *vdec); 443 444 void vdec_reset_userdata_fifo(struct vdec_s *vdec, int bInit); 445 446 struct vdec_s *vdec_get_vdec_by_id(int vdec_id); 447 448 #ifdef VDEC_DEBUG_SUPPORT 449 extern void vdec_set_step_mode(void); 450 #endif 451 int vdec_get_debug_flags(void); 452 453 void VDEC_PRINT_FUN_LINENO(const char *fun, int line); 454 455 456 unsigned char is_mult_inc(unsigned int); 457 458 int vdec_get_status(struct vdec_s *vdec); 459 460 void vdec_set_timestamp(struct vdec_s *vdec, u64 timestamp); 461 462 extern u32 vdec_get_frame_vdec(struct vdec_s *vdec, struct vframe_counter_s *tmpbuf); 463 464 int vdec_get_frame_num(struct vdec_s *vdec); 465 466 int stream_buffer_status_show(char *buf, 467 int (*callback) (struct stream_buf_s *, char *)); 468 469 #endif /* VDEC_H */ 470