| .. | .. |
|---|
| 22 | 22 | #include <linux/reset.h> |
|---|
| 23 | 23 | #include <linux/irqreturn.h> |
|---|
| 24 | 24 | #include <linux/poll.h> |
|---|
| 25 | +#include <linux/platform_device.h> |
|---|
| 25 | 26 | #include <soc/rockchip/pm_domains.h> |
|---|
| 26 | 27 | |
|---|
| 27 | 28 | #define MHZ (1000 * 1000) |
|---|
| .. | .. |
|---|
| 41 | 42 | /* grf mask for get value */ |
|---|
| 42 | 43 | #define MPP_GRF_VAL_MASK (0xFFFF) |
|---|
| 43 | 44 | |
|---|
| 45 | +/* max 4 cores supported */ |
|---|
| 46 | +#define MPP_MAX_CORE_NUM (4) |
|---|
| 47 | + |
|---|
| 44 | 48 | /** |
|---|
| 45 | 49 | * Device type: classified by hardware feature |
|---|
| 46 | 50 | */ |
|---|
| .. | .. |
|---|
| 48 | 52 | MPP_DEVICE_VDPU1 = 0, /* 0x00000001 */ |
|---|
| 49 | 53 | MPP_DEVICE_VDPU2 = 1, /* 0x00000002 */ |
|---|
| 50 | 54 | MPP_DEVICE_VDPU1_PP = 2, /* 0x00000004 */ |
|---|
| 51 | | - MPP_DEVICE_VDPU2_PP = 3, /* 0x00000008 */ |
|---|
| 55 | + MPP_DEVICE_VDPU2_PP = 3, /* 0x00000008 */ |
|---|
| 56 | + MPP_DEVICE_AV1DEC = 4, /* 0x00000010 */ |
|---|
| 52 | 57 | |
|---|
| 53 | 58 | MPP_DEVICE_HEVC_DEC = 8, /* 0x00000100 */ |
|---|
| 54 | 59 | MPP_DEVICE_RKVDEC = 9, /* 0x00000200 */ |
|---|
| 55 | 60 | MPP_DEVICE_AVSPLUS_DEC = 12, /* 0x00001000 */ |
|---|
| 56 | | - MPP_DEVICE_JPGDEC = 13, /* 0x00002000 */ |
|---|
| 61 | + MPP_DEVICE_RKJPEGD = 13, /* 0x00002000 */ |
|---|
| 57 | 62 | |
|---|
| 58 | 63 | MPP_DEVICE_RKVENC = 16, /* 0x00010000 */ |
|---|
| 59 | 64 | MPP_DEVICE_VEPU1 = 17, /* 0x00020000 */ |
|---|
| 60 | 65 | MPP_DEVICE_VEPU2 = 18, /* 0x00040000 */ |
|---|
| 66 | + MPP_DEVICE_VEPU2_JPEG = 19, /* 0x00080000 */ |
|---|
| 61 | 67 | MPP_DEVICE_VEPU22 = 24, /* 0x01000000 */ |
|---|
| 62 | 68 | |
|---|
| 63 | 69 | MPP_DEVICE_IEP2 = 28, /* 0x10000000 */ |
|---|
| .. | .. |
|---|
| 81 | 87 | MPP_DRIVER_IEP2, |
|---|
| 82 | 88 | MPP_DRIVER_JPGDEC, |
|---|
| 83 | 89 | MPP_DRIVER_RKVDEC2, |
|---|
| 84 | | - MPP_DRIVER_VDPP, |
|---|
| 85 | 90 | MPP_DRIVER_RKVENC2, |
|---|
| 91 | + MPP_DRIVER_AV1DEC, |
|---|
| 92 | + MPP_DRIVER_VDPP, |
|---|
| 86 | 93 | MPP_DRIVER_BUTT, |
|---|
| 87 | 94 | }; |
|---|
| 88 | 95 | |
|---|
| .. | .. |
|---|
| 107 | 114 | MPP_CMD_SET_REG_READ = MPP_CMD_SEND_BASE + 1, |
|---|
| 108 | 115 | MPP_CMD_SET_REG_ADDR_OFFSET = MPP_CMD_SEND_BASE + 2, |
|---|
| 109 | 116 | MPP_CMD_SET_RCB_INFO = MPP_CMD_SEND_BASE + 3, |
|---|
| 117 | + MPP_CMD_SET_SESSION_FD = MPP_CMD_SEND_BASE + 4, |
|---|
| 110 | 118 | MPP_CMD_SEND_BUTT, |
|---|
| 111 | 119 | |
|---|
| 112 | 120 | MPP_CMD_POLL_BASE = 0x300, |
|---|
| 113 | 121 | MPP_CMD_POLL_HW_FINISH = MPP_CMD_POLL_BASE + 0, |
|---|
| 122 | + MPP_CMD_POLL_HW_IRQ = MPP_CMD_POLL_BASE + 1, |
|---|
| 114 | 123 | MPP_CMD_POLL_BUTT, |
|---|
| 115 | 124 | |
|---|
| 116 | 125 | MPP_CMD_CONTROL_BASE = 0x400, |
|---|
| .. | .. |
|---|
| 118 | 127 | MPP_CMD_TRANS_FD_TO_IOVA = MPP_CMD_CONTROL_BASE + 1, |
|---|
| 119 | 128 | MPP_CMD_RELEASE_FD = MPP_CMD_CONTROL_BASE + 2, |
|---|
| 120 | 129 | MPP_CMD_SEND_CODEC_INFO = MPP_CMD_CONTROL_BASE + 3, |
|---|
| 121 | | - MPP_CMD_SET_ERR_REF_HACK = MPP_CMD_CONTROL_BASE + 4, |
|---|
| 122 | 130 | MPP_CMD_CONTROL_BUTT, |
|---|
| 123 | 131 | |
|---|
| 124 | 132 | MPP_CMD_BUTT, |
|---|
| .. | .. |
|---|
| 181 | 189 | CODEC_INFO_FLAG_BUTT, |
|---|
| 182 | 190 | }; |
|---|
| 183 | 191 | |
|---|
| 192 | +struct mpp_task; |
|---|
| 193 | +struct mpp_session; |
|---|
| 194 | +struct mpp_dma_session; |
|---|
| 195 | +struct mpp_taskqueue; |
|---|
| 196 | +struct iommu_domain; |
|---|
| 197 | + |
|---|
| 184 | 198 | /* data common struct for parse out */ |
|---|
| 185 | 199 | struct mpp_request { |
|---|
| 186 | 200 | __u32 cmd; |
|---|
| .. | .. |
|---|
| 192 | 206 | |
|---|
| 193 | 207 | /* struct use to collect task set and poll message */ |
|---|
| 194 | 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 | + |
|---|
| 195 | 222 | u32 flags; |
|---|
| 196 | 223 | u32 req_cnt; |
|---|
| 197 | | - struct mpp_request reqs[MPP_MAX_MSG_NUM]; |
|---|
| 198 | 224 | u32 set_cnt; |
|---|
| 199 | 225 | u32 poll_cnt; |
|---|
| 226 | + |
|---|
| 227 | + struct mpp_request reqs[MPP_MAX_MSG_NUM]; |
|---|
| 228 | + struct mpp_request *poll_req; |
|---|
| 200 | 229 | }; |
|---|
| 201 | 230 | |
|---|
| 202 | 231 | struct mpp_grf_info { |
|---|
| 203 | 232 | u32 offset; |
|---|
| 204 | 233 | u32 val; |
|---|
| 205 | | - |
|---|
| 206 | | - /* close mem when module is not working*/ |
|---|
| 207 | | - u32 mem_offset; |
|---|
| 208 | | - u32 val_mem_on; |
|---|
| 209 | | - u32 val_mem_off; |
|---|
| 210 | | - |
|---|
| 211 | 234 | struct regmap *grf; |
|---|
| 212 | 235 | }; |
|---|
| 213 | 236 | |
|---|
| .. | .. |
|---|
| 289 | 312 | bool is_dup; |
|---|
| 290 | 313 | }; |
|---|
| 291 | 314 | |
|---|
| 292 | | -struct mpp_dma_session; |
|---|
| 293 | | - |
|---|
| 294 | | -struct mpp_taskqueue; |
|---|
| 295 | 315 | |
|---|
| 296 | 316 | struct mpp_dev { |
|---|
| 297 | 317 | struct device *dev; |
|---|
| .. | .. |
|---|
| 311 | 331 | * Default 1 means normal hardware can only accept one task at once. |
|---|
| 312 | 332 | */ |
|---|
| 313 | 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; |
|---|
| 314 | 341 | |
|---|
| 315 | 342 | int irq; |
|---|
| 343 | + bool is_irq_startup; |
|---|
| 316 | 344 | u32 irq_status; |
|---|
| 317 | 345 | |
|---|
| 318 | 346 | void __iomem *reg_base; |
|---|
| 319 | 347 | struct mpp_grf_info *grf_info; |
|---|
| 320 | 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; |
|---|
| 321 | 352 | |
|---|
| 322 | 353 | atomic_t reset_request; |
|---|
| 323 | 354 | atomic_t session_index; |
|---|
| .. | .. |
|---|
| 330 | 361 | struct mpp_taskqueue *queue; |
|---|
| 331 | 362 | struct mpp_reset_group *reset_group; |
|---|
| 332 | 363 | /* point to MPP Service */ |
|---|
| 333 | | - struct platform_device *pdev_srv; |
|---|
| 334 | 364 | struct mpp_service *srv; |
|---|
| 335 | 365 | |
|---|
| 366 | + /* multi-core data */ |
|---|
| 336 | 367 | struct list_head queue_link; |
|---|
| 368 | + s32 core_id; |
|---|
| 337 | 369 | |
|---|
| 338 | 370 | /* common per-device procfs */ |
|---|
| 371 | + u32 disable; |
|---|
| 339 | 372 | u32 timing_check; |
|---|
| 340 | 373 | }; |
|---|
| 341 | | - |
|---|
| 342 | | -struct mpp_task; |
|---|
| 343 | 374 | |
|---|
| 344 | 375 | struct mpp_session { |
|---|
| 345 | 376 | enum MPP_DEVICE_TYPE device_type; |
|---|
| .. | .. |
|---|
| 379 | 410 | int (*wait_result)(struct mpp_session *session, |
|---|
| 380 | 411 | struct mpp_task_msgs *msgs); |
|---|
| 381 | 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; |
|---|
| 382 | 419 | }; |
|---|
| 383 | 420 | |
|---|
| 384 | 421 | /* task state in work thread */ |
|---|
| .. | .. |
|---|
| 452 | 489 | /* hardware info for current task */ |
|---|
| 453 | 490 | struct mpp_hw_info *hw_info; |
|---|
| 454 | 491 | u32 task_index; |
|---|
| 492 | + u32 task_id; |
|---|
| 455 | 493 | u32 *reg; |
|---|
| 456 | | - /* hw cycles */ |
|---|
| 457 | | - u32 hw_cycles; |
|---|
| 458 | 494 | /* event for session wait thread */ |
|---|
| 459 | 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; |
|---|
| 460 | 502 | }; |
|---|
| 461 | 503 | |
|---|
| 462 | 504 | struct mpp_taskqueue { |
|---|
| .. | .. |
|---|
| 473 | 515 | struct list_head session_detach; |
|---|
| 474 | 516 | atomic_t detach_count; |
|---|
| 475 | 517 | |
|---|
| 518 | + atomic_t task_id; |
|---|
| 476 | 519 | /* lock for pending list */ |
|---|
| 477 | 520 | struct mutex pending_lock; |
|---|
| 478 | 521 | struct list_head pending_list; |
|---|
| .. | .. |
|---|
| 494 | 537 | */ |
|---|
| 495 | 538 | u32 task_capacity; |
|---|
| 496 | 539 | |
|---|
| 497 | | - /* |
|---|
| 498 | | - * when we need to set grf_mem config to close mem shared by combo modules, |
|---|
| 499 | | - * use runtime_cnt to make sure every combo module are not working |
|---|
| 500 | | - */ |
|---|
| 501 | | - /* lock for runtime counting */ |
|---|
| 502 | | - struct mutex ref_lock; |
|---|
| 503 | | - atomic_t runtime_cnt; |
|---|
| 504 | | - |
|---|
| 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; |
|---|
| 505 | 548 | }; |
|---|
| 506 | 549 | |
|---|
| 507 | 550 | struct mpp_reset_group { |
|---|
| .. | .. |
|---|
| 639 | 682 | struct mpp_task *task); |
|---|
| 640 | 683 | int mpp_task_dump_reg(struct mpp_dev *mpp, |
|---|
| 641 | 684 | struct mpp_task *task); |
|---|
| 642 | | -int mpp_task_dump_hw_reg(struct mpp_dev *mpp, |
|---|
| 643 | | - struct mpp_task *task); |
|---|
| 685 | +int mpp_task_dump_hw_reg(struct mpp_dev *mpp); |
|---|
| 644 | 686 | void mpp_task_dump_timing(struct mpp_task *task, s64 time_diff); |
|---|
| 687 | + |
|---|
| 645 | 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); |
|---|
| 646 | 691 | |
|---|
| 647 | 692 | void mpp_session_deinit(struct mpp_session *session); |
|---|
| 648 | 693 | void mpp_session_cleanup_detach(struct mpp_taskqueue *queue, |
|---|
| 649 | 694 | struct kthread_work *work); |
|---|
| 650 | 695 | |
|---|
| 696 | +int mpp_taskqueue_pending_to_run(struct mpp_taskqueue *queue, struct mpp_task *task); |
|---|
| 697 | + |
|---|
| 651 | 698 | int mpp_dev_probe(struct mpp_dev *mpp, |
|---|
| 652 | 699 | struct platform_device *pdev); |
|---|
| 653 | 700 | int mpp_dev_remove(struct mpp_dev *mpp); |
|---|
| 701 | +void mpp_dev_shutdown(struct platform_device *pdev); |
|---|
| 654 | 702 | int mpp_dev_register_srv(struct mpp_dev *mpp, struct mpp_service *srv); |
|---|
| 655 | 703 | |
|---|
| 656 | 704 | int mpp_power_on(struct mpp_dev *mpp); |
|---|
| .. | .. |
|---|
| 807 | 855 | return rockchip_pmu_idle_request(mpp->dev, idle); |
|---|
| 808 | 856 | } |
|---|
| 809 | 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 | + |
|---|
| 810 | 865 | #ifdef CONFIG_ROCKCHIP_MPP_PROC_FS |
|---|
| 811 | 866 | struct proc_dir_entry * |
|---|
| 812 | 867 | mpp_procfs_create_u32(const char *name, umode_t mode, |
|---|
| .. | .. |
|---|
| 841 | 896 | extern struct platform_driver rockchip_iep2_driver; |
|---|
| 842 | 897 | extern struct platform_driver rockchip_jpgdec_driver; |
|---|
| 843 | 898 | extern struct platform_driver rockchip_rkvdec2_driver; |
|---|
| 844 | | -extern struct platform_driver rockchip_vdpp_driver; |
|---|
| 845 | 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; |
|---|
| 846 | 907 | |
|---|
| 847 | 908 | #endif |
|---|