| .. | .. |
|---|
| 22 | 22 | #include <linux/reset.h> |
|---|
| 23 | 23 | #include <linux/irqreturn.h> |
|---|
| 24 | 24 | #include <linux/poll.h> |
|---|
| 25 | +#include <linux/platform_device.h> |
|---|
| 26 | +#include <soc/rockchip/pm_domains.h> |
|---|
| 25 | 27 | |
|---|
| 26 | | -#define MHZ (1000 * 1000) |
|---|
| 28 | +#define MHZ (1000 * 1000) |
|---|
| 29 | +#define MPP_WORK_TIMEOUT_DELAY (500) |
|---|
| 27 | 30 | |
|---|
| 28 | 31 | #define MPP_MAX_MSG_NUM (16) |
|---|
| 29 | 32 | #define MPP_MAX_REG_TRANS_NUM (60) |
|---|
| .. | .. |
|---|
| 39 | 42 | /* grf mask for get value */ |
|---|
| 40 | 43 | #define MPP_GRF_VAL_MASK (0xFFFF) |
|---|
| 41 | 44 | |
|---|
| 45 | +/* max 4 cores supported */ |
|---|
| 46 | +#define MPP_MAX_CORE_NUM (4) |
|---|
| 47 | + |
|---|
| 42 | 48 | /** |
|---|
| 43 | 49 | * Device type: classified by hardware feature |
|---|
| 44 | 50 | */ |
|---|
| .. | .. |
|---|
| 46 | 52 | MPP_DEVICE_VDPU1 = 0, /* 0x00000001 */ |
|---|
| 47 | 53 | MPP_DEVICE_VDPU2 = 1, /* 0x00000002 */ |
|---|
| 48 | 54 | MPP_DEVICE_VDPU1_PP = 2, /* 0x00000004 */ |
|---|
| 49 | | - MPP_DEVICE_VDPU2_PP = 3, /* 0x00000008 */ |
|---|
| 55 | + MPP_DEVICE_VDPU2_PP = 3, /* 0x00000008 */ |
|---|
| 56 | + MPP_DEVICE_AV1DEC = 4, /* 0x00000010 */ |
|---|
| 50 | 57 | |
|---|
| 51 | 58 | MPP_DEVICE_HEVC_DEC = 8, /* 0x00000100 */ |
|---|
| 52 | 59 | MPP_DEVICE_RKVDEC = 9, /* 0x00000200 */ |
|---|
| 53 | 60 | MPP_DEVICE_AVSPLUS_DEC = 12, /* 0x00001000 */ |
|---|
| 54 | | - MPP_DEVICE_JPGDEC = 13, /* 0x00002000 */ |
|---|
| 61 | + MPP_DEVICE_RKJPEGD = 13, /* 0x00002000 */ |
|---|
| 55 | 62 | |
|---|
| 56 | 63 | MPP_DEVICE_RKVENC = 16, /* 0x00010000 */ |
|---|
| 57 | 64 | MPP_DEVICE_VEPU1 = 17, /* 0x00020000 */ |
|---|
| 58 | 65 | MPP_DEVICE_VEPU2 = 18, /* 0x00040000 */ |
|---|
| 66 | + MPP_DEVICE_VEPU2_JPEG = 19, /* 0x00080000 */ |
|---|
| 59 | 67 | MPP_DEVICE_VEPU22 = 24, /* 0x01000000 */ |
|---|
| 60 | 68 | |
|---|
| 61 | 69 | MPP_DEVICE_IEP2 = 28, /* 0x10000000 */ |
|---|
| .. | .. |
|---|
| 79 | 87 | MPP_DRIVER_IEP2, |
|---|
| 80 | 88 | MPP_DRIVER_JPGDEC, |
|---|
| 81 | 89 | MPP_DRIVER_RKVDEC2, |
|---|
| 82 | | - MPP_DRIVER_VDPP, |
|---|
| 83 | 90 | MPP_DRIVER_RKVENC2, |
|---|
| 91 | + MPP_DRIVER_AV1DEC, |
|---|
| 92 | + MPP_DRIVER_VDPP, |
|---|
| 84 | 93 | MPP_DRIVER_BUTT, |
|---|
| 85 | 94 | }; |
|---|
| 86 | 95 | |
|---|
| .. | .. |
|---|
| 105 | 114 | MPP_CMD_SET_REG_READ = MPP_CMD_SEND_BASE + 1, |
|---|
| 106 | 115 | MPP_CMD_SET_REG_ADDR_OFFSET = MPP_CMD_SEND_BASE + 2, |
|---|
| 107 | 116 | MPP_CMD_SET_RCB_INFO = MPP_CMD_SEND_BASE + 3, |
|---|
| 117 | + MPP_CMD_SET_SESSION_FD = MPP_CMD_SEND_BASE + 4, |
|---|
| 108 | 118 | MPP_CMD_SEND_BUTT, |
|---|
| 109 | 119 | |
|---|
| 110 | 120 | MPP_CMD_POLL_BASE = 0x300, |
|---|
| 111 | 121 | MPP_CMD_POLL_HW_FINISH = MPP_CMD_POLL_BASE + 0, |
|---|
| 122 | + MPP_CMD_POLL_HW_IRQ = MPP_CMD_POLL_BASE + 1, |
|---|
| 112 | 123 | MPP_CMD_POLL_BUTT, |
|---|
| 113 | 124 | |
|---|
| 114 | 125 | MPP_CMD_CONTROL_BASE = 0x400, |
|---|
| .. | .. |
|---|
| 178 | 189 | CODEC_INFO_FLAG_BUTT, |
|---|
| 179 | 190 | }; |
|---|
| 180 | 191 | |
|---|
| 192 | +struct mpp_task; |
|---|
| 193 | +struct mpp_session; |
|---|
| 194 | +struct mpp_dma_session; |
|---|
| 195 | +struct mpp_taskqueue; |
|---|
| 196 | +struct iommu_domain; |
|---|
| 197 | + |
|---|
| 181 | 198 | /* data common struct for parse out */ |
|---|
| 182 | 199 | struct mpp_request { |
|---|
| 183 | 200 | __u32 cmd; |
|---|
| .. | .. |
|---|
| 189 | 206 | |
|---|
| 190 | 207 | /* struct use to collect task set and poll message */ |
|---|
| 191 | 208 | struct mpp_task_msgs { |
|---|
| 209 | + /* for ioctl msgs bat process */ |
|---|
| 210 | + struct list_head list; |
|---|
| 211 | + struct list_head list_session; |
|---|
| 212 | + |
|---|
| 213 | + struct mpp_session *session; |
|---|
| 214 | + struct mpp_taskqueue *queue; |
|---|
| 215 | + struct mpp_task *task; |
|---|
| 216 | + struct mpp_dev *mpp; |
|---|
| 217 | + |
|---|
| 218 | + /* for fd reference */ |
|---|
| 219 | + int ext_fd; |
|---|
| 220 | + struct fd f; |
|---|
| 221 | + |
|---|
| 192 | 222 | u32 flags; |
|---|
| 193 | 223 | u32 req_cnt; |
|---|
| 194 | | - struct mpp_request reqs[MPP_MAX_MSG_NUM]; |
|---|
| 195 | 224 | u32 set_cnt; |
|---|
| 196 | 225 | u32 poll_cnt; |
|---|
| 226 | + |
|---|
| 227 | + struct mpp_request reqs[MPP_MAX_MSG_NUM]; |
|---|
| 228 | + struct mpp_request *poll_req; |
|---|
| 197 | 229 | }; |
|---|
| 198 | 230 | |
|---|
| 199 | 231 | struct mpp_grf_info { |
|---|
| .. | .. |
|---|
| 255 | 287 | u32 reduce_rate_hz; |
|---|
| 256 | 288 | /* record last used rate */ |
|---|
| 257 | 289 | u32 used_rate_hz; |
|---|
| 290 | + u32 real_rate_hz; |
|---|
| 258 | 291 | }; |
|---|
| 259 | 292 | |
|---|
| 260 | 293 | struct mpp_dev_var { |
|---|
| .. | .. |
|---|
| 279 | 312 | bool is_dup; |
|---|
| 280 | 313 | }; |
|---|
| 281 | 314 | |
|---|
| 282 | | -struct mpp_dma_session; |
|---|
| 283 | | - |
|---|
| 284 | | -struct mpp_taskqueue; |
|---|
| 285 | 315 | |
|---|
| 286 | 316 | struct mpp_dev { |
|---|
| 287 | 317 | struct device *dev; |
|---|
| .. | .. |
|---|
| 293 | 323 | struct kthread_work work; |
|---|
| 294 | 324 | /* the flag for get/get/reduce freq */ |
|---|
| 295 | 325 | bool auto_freq_en; |
|---|
| 326 | + /* the flag for pmu idle request before device reset */ |
|---|
| 327 | + bool skip_idle; |
|---|
| 296 | 328 | |
|---|
| 297 | 329 | /* |
|---|
| 298 | 330 | * The task capacity is the task queue length that hardware can accept. |
|---|
| 299 | 331 | * Default 1 means normal hardware can only accept one task at once. |
|---|
| 300 | 332 | */ |
|---|
| 301 | 333 | u32 task_capacity; |
|---|
| 334 | + /* |
|---|
| 335 | + * The message capacity is the max message parallel process capacity. |
|---|
| 336 | + * Default 1 means normal hardware can only accept one message at one |
|---|
| 337 | + * shot ioctl. |
|---|
| 338 | + * Multi-core hardware can accept more message at one shot ioctl. |
|---|
| 339 | + */ |
|---|
| 340 | + u32 msgs_cap; |
|---|
| 302 | 341 | |
|---|
| 303 | 342 | int irq; |
|---|
| 343 | + bool is_irq_startup; |
|---|
| 304 | 344 | u32 irq_status; |
|---|
| 305 | 345 | |
|---|
| 306 | 346 | void __iomem *reg_base; |
|---|
| 307 | 347 | struct mpp_grf_info *grf_info; |
|---|
| 308 | 348 | struct mpp_iommu_info *iommu_info; |
|---|
| 349 | + int (*fault_handler)(struct iommu_domain *iommu, struct device *iommu_dev, |
|---|
| 350 | + unsigned long iova, int status, void *arg); |
|---|
| 351 | + resource_size_t io_base; |
|---|
| 309 | 352 | |
|---|
| 310 | 353 | atomic_t reset_request; |
|---|
| 311 | 354 | atomic_t session_index; |
|---|
| .. | .. |
|---|
| 318 | 361 | struct mpp_taskqueue *queue; |
|---|
| 319 | 362 | struct mpp_reset_group *reset_group; |
|---|
| 320 | 363 | /* point to MPP Service */ |
|---|
| 321 | | - struct platform_device *pdev_srv; |
|---|
| 322 | 364 | struct mpp_service *srv; |
|---|
| 323 | 365 | |
|---|
| 366 | + /* multi-core data */ |
|---|
| 324 | 367 | struct list_head queue_link; |
|---|
| 325 | | -}; |
|---|
| 368 | + s32 core_id; |
|---|
| 326 | 369 | |
|---|
| 327 | | -struct mpp_task; |
|---|
| 370 | + /* common per-device procfs */ |
|---|
| 371 | + u32 disable; |
|---|
| 372 | + u32 timing_check; |
|---|
| 373 | +}; |
|---|
| 328 | 374 | |
|---|
| 329 | 375 | struct mpp_session { |
|---|
| 330 | 376 | enum MPP_DEVICE_TYPE device_type; |
|---|
| .. | .. |
|---|
| 338 | 384 | struct mutex pending_lock; |
|---|
| 339 | 385 | /* task pending list in session */ |
|---|
| 340 | 386 | struct list_head pending_list; |
|---|
| 341 | | - /* lock for session task done list */ |
|---|
| 342 | | - struct mutex done_lock; |
|---|
| 343 | | - /* task done list in session */ |
|---|
| 344 | | - struct list_head done_list; |
|---|
| 345 | 387 | |
|---|
| 346 | | - /* event for session wait thread */ |
|---|
| 347 | | - wait_queue_head_t wait; |
|---|
| 348 | 388 | pid_t pid; |
|---|
| 349 | 389 | atomic_t task_count; |
|---|
| 350 | 390 | atomic_t release_request; |
|---|
| .. | .. |
|---|
| 370 | 410 | int (*wait_result)(struct mpp_session *session, |
|---|
| 371 | 411 | struct mpp_task_msgs *msgs); |
|---|
| 372 | 412 | void (*deinit)(struct mpp_session *session); |
|---|
| 413 | + |
|---|
| 414 | + /* max message count */ |
|---|
| 415 | + int msgs_cnt; |
|---|
| 416 | + struct list_head list_msgs; |
|---|
| 417 | + struct list_head list_msgs_idle; |
|---|
| 418 | + spinlock_t lock_msgs; |
|---|
| 373 | 419 | }; |
|---|
| 374 | 420 | |
|---|
| 375 | 421 | /* task state in work thread */ |
|---|
| .. | .. |
|---|
| 387 | 433 | TASK_STATE_ABORT = 9, |
|---|
| 388 | 434 | TASK_STATE_ABORT_READY = 10, |
|---|
| 389 | 435 | TASK_STATE_PROC_DONE = 11, |
|---|
| 436 | + |
|---|
| 437 | + /* timing debug state */ |
|---|
| 438 | + TASK_TIMING_CREATE = 16, |
|---|
| 439 | + TASK_TIMING_CREATE_END = 17, |
|---|
| 440 | + TASK_TIMING_PENDING = 18, |
|---|
| 441 | + TASK_TIMING_RUN = 19, |
|---|
| 442 | + TASK_TIMING_TO_SCHED = 20, |
|---|
| 443 | + TASK_TIMING_RUN_END = 21, |
|---|
| 444 | + TASK_TIMING_IRQ = 22, |
|---|
| 445 | + TASK_TIMING_TO_CANCEL = 23, |
|---|
| 446 | + TASK_TIMING_ISR = 24, |
|---|
| 447 | + TASK_TIMING_FINISH = 25, |
|---|
| 390 | 448 | }; |
|---|
| 391 | 449 | |
|---|
| 392 | 450 | /* The context for the a task */ |
|---|
| .. | .. |
|---|
| 413 | 471 | struct kref ref; |
|---|
| 414 | 472 | |
|---|
| 415 | 473 | /* record context running start time */ |
|---|
| 416 | | - struct timeval start; |
|---|
| 474 | + ktime_t start; |
|---|
| 475 | + ktime_t part; |
|---|
| 476 | + |
|---|
| 477 | + /* debug timing */ |
|---|
| 478 | + ktime_t on_create; |
|---|
| 479 | + ktime_t on_create_end; |
|---|
| 480 | + ktime_t on_pending; |
|---|
| 481 | + ktime_t on_run; |
|---|
| 482 | + ktime_t on_sched_timeout; |
|---|
| 483 | + ktime_t on_run_end; |
|---|
| 484 | + ktime_t on_irq; |
|---|
| 485 | + ktime_t on_cancel_timeout; |
|---|
| 486 | + ktime_t on_isr; |
|---|
| 487 | + ktime_t on_finish; |
|---|
| 488 | + |
|---|
| 417 | 489 | /* hardware info for current task */ |
|---|
| 418 | 490 | struct mpp_hw_info *hw_info; |
|---|
| 419 | 491 | u32 task_index; |
|---|
| 492 | + u32 task_id; |
|---|
| 420 | 493 | u32 *reg; |
|---|
| 494 | + /* event for session wait thread */ |
|---|
| 495 | + wait_queue_head_t wait; |
|---|
| 496 | + |
|---|
| 497 | + /* for multi-core */ |
|---|
| 498 | + struct mpp_dev *mpp; |
|---|
| 499 | + s32 core_id; |
|---|
| 500 | + /* hw cycles */ |
|---|
| 501 | + u32 hw_cycles; |
|---|
| 421 | 502 | }; |
|---|
| 422 | 503 | |
|---|
| 423 | 504 | struct mpp_taskqueue { |
|---|
| .. | .. |
|---|
| 432 | 513 | struct list_head session_attach; |
|---|
| 433 | 514 | /* link to session session_link for detached sessions */ |
|---|
| 434 | 515 | struct list_head session_detach; |
|---|
| 435 | | - u32 detach_count; |
|---|
| 516 | + atomic_t detach_count; |
|---|
| 436 | 517 | |
|---|
| 518 | + atomic_t task_id; |
|---|
| 437 | 519 | /* lock for pending list */ |
|---|
| 438 | 520 | struct mutex pending_lock; |
|---|
| 439 | 521 | struct list_head pending_list; |
|---|
| .. | .. |
|---|
| 454 | 536 | * device task capacity which is attached to the taskqueue |
|---|
| 455 | 537 | */ |
|---|
| 456 | 538 | u32 task_capacity; |
|---|
| 539 | + |
|---|
| 540 | + /* multi-core task distribution */ |
|---|
| 541 | + atomic_t reset_request; |
|---|
| 542 | + struct mpp_dev *cores[MPP_MAX_CORE_NUM]; |
|---|
| 543 | + unsigned long core_idle; |
|---|
| 544 | + u32 core_id_max; |
|---|
| 545 | + u32 core_count; |
|---|
| 546 | + unsigned long dev_active_flags; |
|---|
| 547 | + u32 iommu_fault; |
|---|
| 457 | 548 | }; |
|---|
| 458 | 549 | |
|---|
| 459 | 550 | struct mpp_reset_group { |
|---|
| .. | .. |
|---|
| 490 | 581 | struct mutex session_lock; |
|---|
| 491 | 582 | struct list_head session_list; |
|---|
| 492 | 583 | u32 session_count; |
|---|
| 584 | + |
|---|
| 585 | + /* global timing record flag */ |
|---|
| 586 | + u32 timing_en; |
|---|
| 493 | 587 | }; |
|---|
| 494 | 588 | |
|---|
| 495 | 589 | /* |
|---|
| .. | .. |
|---|
| 580 | 674 | struct mpp_task *task); |
|---|
| 581 | 675 | int mpp_task_finish(struct mpp_session *session, |
|---|
| 582 | 676 | struct mpp_task *task); |
|---|
| 677 | +void mpp_task_run_begin(struct mpp_task *task, u32 timing_en, u32 timeout); |
|---|
| 678 | +void mpp_task_run_end(struct mpp_task *task, u32 timing_en); |
|---|
| 583 | 679 | int mpp_task_finalize(struct mpp_session *session, |
|---|
| 584 | 680 | struct mpp_task *task); |
|---|
| 585 | 681 | int mpp_task_dump_mem_region(struct mpp_dev *mpp, |
|---|
| 586 | 682 | struct mpp_task *task); |
|---|
| 587 | 683 | int mpp_task_dump_reg(struct mpp_dev *mpp, |
|---|
| 588 | 684 | struct mpp_task *task); |
|---|
| 589 | | -int mpp_task_dump_hw_reg(struct mpp_dev *mpp, |
|---|
| 590 | | - struct mpp_task *task); |
|---|
| 685 | +int mpp_task_dump_hw_reg(struct mpp_dev *mpp); |
|---|
| 686 | +void mpp_task_dump_timing(struct mpp_task *task, s64 time_diff); |
|---|
| 591 | 687 | |
|---|
| 592 | | -int mpp_session_deinit(struct mpp_session *session); |
|---|
| 688 | +void mpp_reg_show(struct mpp_dev *mpp, u32 offset); |
|---|
| 689 | +void mpp_reg_show_range(struct mpp_dev *mpp, u32 start, u32 end); |
|---|
| 690 | +void mpp_free_task(struct kref *ref); |
|---|
| 691 | + |
|---|
| 692 | +void mpp_session_deinit(struct mpp_session *session); |
|---|
| 693 | +void mpp_session_cleanup_detach(struct mpp_taskqueue *queue, |
|---|
| 694 | + struct kthread_work *work); |
|---|
| 695 | + |
|---|
| 696 | +int mpp_taskqueue_pending_to_run(struct mpp_taskqueue *queue, struct mpp_task *task); |
|---|
| 593 | 697 | |
|---|
| 594 | 698 | int mpp_dev_probe(struct mpp_dev *mpp, |
|---|
| 595 | 699 | struct platform_device *pdev); |
|---|
| 596 | 700 | int mpp_dev_remove(struct mpp_dev *mpp); |
|---|
| 701 | +void mpp_dev_shutdown(struct platform_device *pdev); |
|---|
| 597 | 702 | int mpp_dev_register_srv(struct mpp_dev *mpp, struct mpp_service *srv); |
|---|
| 598 | 703 | |
|---|
| 599 | 704 | int mpp_power_on(struct mpp_dev *mpp); |
|---|
| .. | .. |
|---|
| 613 | 718 | |
|---|
| 614 | 719 | int mpp_time_record(struct mpp_task *task); |
|---|
| 615 | 720 | int mpp_time_diff(struct mpp_task *task); |
|---|
| 721 | +int mpp_time_diff_with_hw_time(struct mpp_task *task, u32 clk_hz); |
|---|
| 722 | +int mpp_time_part_diff(struct mpp_task *task); |
|---|
| 616 | 723 | |
|---|
| 617 | 724 | int mpp_write_req(struct mpp_dev *mpp, u32 *regs, |
|---|
| 618 | 725 | u32 start_idx, u32 end_idx, u32 en_idx); |
|---|
| .. | .. |
|---|
| 740 | 847 | return 0; |
|---|
| 741 | 848 | } |
|---|
| 742 | 849 | |
|---|
| 850 | +static inline int mpp_pmu_idle_request(struct mpp_dev *mpp, bool idle) |
|---|
| 851 | +{ |
|---|
| 852 | + if (mpp->skip_idle) |
|---|
| 853 | + return 0; |
|---|
| 854 | + |
|---|
| 855 | + return rockchip_pmu_idle_request(mpp->dev, idle); |
|---|
| 856 | +} |
|---|
| 857 | + |
|---|
| 858 | +static inline struct mpp_dev * |
|---|
| 859 | +mpp_get_task_used_device(const struct mpp_task *task, |
|---|
| 860 | + const struct mpp_session *session) |
|---|
| 861 | +{ |
|---|
| 862 | + return task->mpp ? task->mpp : session->mpp; |
|---|
| 863 | +} |
|---|
| 864 | + |
|---|
| 743 | 865 | #ifdef CONFIG_ROCKCHIP_MPP_PROC_FS |
|---|
| 744 | 866 | struct proc_dir_entry * |
|---|
| 745 | 867 | mpp_procfs_create_u32(const char *name, umode_t mode, |
|---|
| 746 | 868 | struct proc_dir_entry *parent, void *data); |
|---|
| 869 | +void mpp_procfs_create_common(struct proc_dir_entry *parent, struct mpp_dev *mpp); |
|---|
| 747 | 870 | #else |
|---|
| 748 | 871 | static inline struct proc_dir_entry * |
|---|
| 749 | 872 | mpp_procfs_create_u32(const char *name, umode_t mode, |
|---|
| 750 | 873 | struct proc_dir_entry *parent, void *data) |
|---|
| 751 | 874 | { |
|---|
| 752 | 875 | return 0; |
|---|
| 876 | +} |
|---|
| 877 | +void mpp_procfs_create_common(struct proc_dir_entry *parent, struct mpp_dev *mpp) |
|---|
| 878 | +{ |
|---|
| 753 | 879 | } |
|---|
| 754 | 880 | #endif |
|---|
| 755 | 881 | |
|---|
| .. | .. |
|---|
| 770 | 896 | extern struct platform_driver rockchip_iep2_driver; |
|---|
| 771 | 897 | extern struct platform_driver rockchip_jpgdec_driver; |
|---|
| 772 | 898 | extern struct platform_driver rockchip_rkvdec2_driver; |
|---|
| 773 | | -extern struct platform_driver rockchip_vdpp_driver; |
|---|
| 774 | 899 | extern struct platform_driver rockchip_rkvenc2_driver; |
|---|
| 900 | +extern struct platform_driver rockchip_av1dec_driver; |
|---|
| 901 | +extern struct platform_driver rockchip_av1_iommu_driver; |
|---|
| 902 | + |
|---|
| 903 | +extern int av1dec_driver_register(struct platform_driver *drv); |
|---|
| 904 | +extern void av1dec_driver_unregister(struct platform_driver *drv); |
|---|
| 905 | +extern struct bus_type av1dec_bus; |
|---|
| 906 | +extern struct platform_driver rockchip_vdpp_driver; |
|---|
| 775 | 907 | |
|---|
| 776 | 908 | #endif |
|---|