.. | .. |
---|
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> |
---|
| 27 | +#include <uapi/linux/rk-mpp.h> |
---|
26 | 28 | |
---|
27 | 29 | #define MHZ (1000 * 1000) |
---|
28 | 30 | #define MPP_WORK_TIMEOUT_DELAY (500) |
---|
.. | .. |
---|
30 | 32 | #define MPP_MAX_MSG_NUM (16) |
---|
31 | 33 | #define MPP_MAX_REG_TRANS_NUM (60) |
---|
32 | 34 | #define MPP_MAX_TASK_CAPACITY (16) |
---|
33 | | -/* define flags for mpp_request */ |
---|
34 | | -#define MPP_FLAGS_MULTI_MSG (0x00000001) |
---|
35 | | -#define MPP_FLAGS_LAST_MSG (0x00000002) |
---|
36 | | -#define MPP_FLAGS_REG_FD_NO_TRANS (0x00000004) |
---|
37 | | -#define MPP_FLAGS_SCL_FD_NO_TRANS (0x00000008) |
---|
38 | | -#define MPP_FLAGS_REG_NO_OFFSET (0x00000010) |
---|
39 | | -#define MPP_FLAGS_SECURE_MODE (0x00010000) |
---|
40 | 35 | |
---|
41 | 36 | /* grf mask for get value */ |
---|
42 | 37 | #define MPP_GRF_VAL_MASK (0xFFFF) |
---|
| 38 | + |
---|
| 39 | +/* max 4 cores supported */ |
---|
| 40 | +#define MPP_MAX_CORE_NUM (4) |
---|
43 | 41 | |
---|
44 | 42 | /** |
---|
45 | 43 | * Device type: classified by hardware feature |
---|
.. | .. |
---|
48 | 46 | MPP_DEVICE_VDPU1 = 0, /* 0x00000001 */ |
---|
49 | 47 | MPP_DEVICE_VDPU2 = 1, /* 0x00000002 */ |
---|
50 | 48 | MPP_DEVICE_VDPU1_PP = 2, /* 0x00000004 */ |
---|
51 | | - MPP_DEVICE_VDPU2_PP = 3, /* 0x00000008 */ |
---|
| 49 | + MPP_DEVICE_VDPU2_PP = 3, /* 0x00000008 */ |
---|
| 50 | + MPP_DEVICE_AV1DEC = 4, /* 0x00000010 */ |
---|
52 | 51 | |
---|
53 | 52 | MPP_DEVICE_HEVC_DEC = 8, /* 0x00000100 */ |
---|
54 | 53 | MPP_DEVICE_RKVDEC = 9, /* 0x00000200 */ |
---|
55 | 54 | MPP_DEVICE_AVSPLUS_DEC = 12, /* 0x00001000 */ |
---|
56 | | - MPP_DEVICE_JPGDEC = 13, /* 0x00002000 */ |
---|
| 55 | + MPP_DEVICE_RKJPEGD = 13, /* 0x00002000 */ |
---|
57 | 56 | |
---|
58 | 57 | MPP_DEVICE_RKVENC = 16, /* 0x00010000 */ |
---|
59 | 58 | MPP_DEVICE_VEPU1 = 17, /* 0x00020000 */ |
---|
60 | 59 | MPP_DEVICE_VEPU2 = 18, /* 0x00040000 */ |
---|
| 60 | + MPP_DEVICE_VEPU2_JPEG = 19, /* 0x00080000 */ |
---|
61 | 61 | MPP_DEVICE_VEPU22 = 24, /* 0x01000000 */ |
---|
62 | 62 | |
---|
63 | 63 | MPP_DEVICE_IEP2 = 28, /* 0x10000000 */ |
---|
.. | .. |
---|
81 | 81 | MPP_DRIVER_IEP2, |
---|
82 | 82 | MPP_DRIVER_JPGDEC, |
---|
83 | 83 | MPP_DRIVER_RKVDEC2, |
---|
84 | | - MPP_DRIVER_VDPP, |
---|
85 | 84 | MPP_DRIVER_RKVENC2, |
---|
| 85 | + MPP_DRIVER_AV1DEC, |
---|
| 86 | + MPP_DRIVER_VDPP, |
---|
86 | 87 | MPP_DRIVER_BUTT, |
---|
87 | | -}; |
---|
88 | | - |
---|
89 | | -/** |
---|
90 | | - * Command type: keep the same as user space |
---|
91 | | - */ |
---|
92 | | -enum MPP_DEV_COMMAND_TYPE { |
---|
93 | | - MPP_CMD_QUERY_BASE = 0, |
---|
94 | | - MPP_CMD_QUERY_HW_SUPPORT = MPP_CMD_QUERY_BASE + 0, |
---|
95 | | - MPP_CMD_QUERY_HW_ID = MPP_CMD_QUERY_BASE + 1, |
---|
96 | | - MPP_CMD_QUERY_CMD_SUPPORT = MPP_CMD_QUERY_BASE + 2, |
---|
97 | | - MPP_CMD_QUERY_BUTT, |
---|
98 | | - |
---|
99 | | - MPP_CMD_INIT_BASE = 0x100, |
---|
100 | | - MPP_CMD_INIT_CLIENT_TYPE = MPP_CMD_INIT_BASE + 0, |
---|
101 | | - MPP_CMD_INIT_DRIVER_DATA = MPP_CMD_INIT_BASE + 1, |
---|
102 | | - MPP_CMD_INIT_TRANS_TABLE = MPP_CMD_INIT_BASE + 2, |
---|
103 | | - MPP_CMD_INIT_BUTT, |
---|
104 | | - |
---|
105 | | - MPP_CMD_SEND_BASE = 0x200, |
---|
106 | | - MPP_CMD_SET_REG_WRITE = MPP_CMD_SEND_BASE + 0, |
---|
107 | | - MPP_CMD_SET_REG_READ = MPP_CMD_SEND_BASE + 1, |
---|
108 | | - MPP_CMD_SET_REG_ADDR_OFFSET = MPP_CMD_SEND_BASE + 2, |
---|
109 | | - MPP_CMD_SET_RCB_INFO = MPP_CMD_SEND_BASE + 3, |
---|
110 | | - MPP_CMD_SEND_BUTT, |
---|
111 | | - |
---|
112 | | - MPP_CMD_POLL_BASE = 0x300, |
---|
113 | | - MPP_CMD_POLL_HW_FINISH = MPP_CMD_POLL_BASE + 0, |
---|
114 | | - MPP_CMD_POLL_BUTT, |
---|
115 | | - |
---|
116 | | - MPP_CMD_CONTROL_BASE = 0x400, |
---|
117 | | - MPP_CMD_RESET_SESSION = MPP_CMD_CONTROL_BASE + 0, |
---|
118 | | - MPP_CMD_TRANS_FD_TO_IOVA = MPP_CMD_CONTROL_BASE + 1, |
---|
119 | | - MPP_CMD_RELEASE_FD = MPP_CMD_CONTROL_BASE + 2, |
---|
120 | | - MPP_CMD_SEND_CODEC_INFO = MPP_CMD_CONTROL_BASE + 3, |
---|
121 | | - MPP_CMD_SET_ERR_REF_HACK = MPP_CMD_CONTROL_BASE + 4, |
---|
122 | | - MPP_CMD_CONTROL_BUTT, |
---|
123 | | - |
---|
124 | | - MPP_CMD_BUTT, |
---|
125 | 88 | }; |
---|
126 | 89 | |
---|
127 | 90 | enum MPP_CLOCK_MODE { |
---|
.. | .. |
---|
181 | 144 | CODEC_INFO_FLAG_BUTT, |
---|
182 | 145 | }; |
---|
183 | 146 | |
---|
184 | | -/* data common struct for parse out */ |
---|
185 | | -struct mpp_request { |
---|
186 | | - __u32 cmd; |
---|
187 | | - __u32 flags; |
---|
188 | | - __u32 size; |
---|
189 | | - __u32 offset; |
---|
190 | | - void __user *data; |
---|
191 | | -}; |
---|
| 147 | +struct mpp_task; |
---|
| 148 | +struct mpp_session; |
---|
| 149 | +struct mpp_dma_session; |
---|
| 150 | +struct mpp_taskqueue; |
---|
| 151 | +struct iommu_domain; |
---|
192 | 152 | |
---|
193 | 153 | /* struct use to collect task set and poll message */ |
---|
194 | 154 | struct mpp_task_msgs { |
---|
| 155 | + /* for ioctl msgs bat process */ |
---|
| 156 | + struct list_head list; |
---|
| 157 | + struct list_head list_session; |
---|
| 158 | + |
---|
| 159 | + struct mpp_session *session; |
---|
| 160 | + struct mpp_taskqueue *queue; |
---|
| 161 | + struct mpp_task *task; |
---|
| 162 | + struct mpp_dev *mpp; |
---|
| 163 | + |
---|
| 164 | + /* for fd reference */ |
---|
| 165 | + int ext_fd; |
---|
| 166 | + struct fd f; |
---|
| 167 | + |
---|
195 | 168 | u32 flags; |
---|
196 | 169 | u32 req_cnt; |
---|
197 | | - struct mpp_request reqs[MPP_MAX_MSG_NUM]; |
---|
198 | 170 | u32 set_cnt; |
---|
199 | 171 | u32 poll_cnt; |
---|
| 172 | + |
---|
| 173 | + struct mpp_request reqs[MPP_MAX_MSG_NUM]; |
---|
| 174 | + struct mpp_request *poll_req; |
---|
200 | 175 | }; |
---|
201 | 176 | |
---|
202 | 177 | struct mpp_grf_info { |
---|
203 | 178 | u32 offset; |
---|
204 | 179 | 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 | 180 | struct regmap *grf; |
---|
212 | 181 | }; |
---|
213 | 182 | |
---|
.. | .. |
---|
289 | 258 | bool is_dup; |
---|
290 | 259 | }; |
---|
291 | 260 | |
---|
292 | | -struct mpp_dma_session; |
---|
293 | | - |
---|
294 | | -struct mpp_taskqueue; |
---|
295 | 261 | |
---|
296 | 262 | struct mpp_dev { |
---|
297 | 263 | struct device *dev; |
---|
.. | .. |
---|
311 | 277 | * Default 1 means normal hardware can only accept one task at once. |
---|
312 | 278 | */ |
---|
313 | 279 | u32 task_capacity; |
---|
| 280 | + /* |
---|
| 281 | + * The message capacity is the max message parallel process capacity. |
---|
| 282 | + * Default 1 means normal hardware can only accept one message at one |
---|
| 283 | + * shot ioctl. |
---|
| 284 | + * Multi-core hardware can accept more message at one shot ioctl. |
---|
| 285 | + */ |
---|
| 286 | + u32 msgs_cap; |
---|
314 | 287 | |
---|
315 | 288 | int irq; |
---|
| 289 | + bool is_irq_startup; |
---|
316 | 290 | u32 irq_status; |
---|
317 | 291 | |
---|
318 | 292 | void __iomem *reg_base; |
---|
319 | 293 | struct mpp_grf_info *grf_info; |
---|
320 | 294 | struct mpp_iommu_info *iommu_info; |
---|
| 295 | + int (*fault_handler)(struct iommu_domain *iommu, struct device *iommu_dev, |
---|
| 296 | + unsigned long iova, int status, void *arg); |
---|
| 297 | + resource_size_t io_base; |
---|
321 | 298 | |
---|
322 | 299 | atomic_t reset_request; |
---|
323 | 300 | atomic_t session_index; |
---|
.. | .. |
---|
330 | 307 | struct mpp_taskqueue *queue; |
---|
331 | 308 | struct mpp_reset_group *reset_group; |
---|
332 | 309 | /* point to MPP Service */ |
---|
333 | | - struct platform_device *pdev_srv; |
---|
334 | 310 | struct mpp_service *srv; |
---|
335 | 311 | |
---|
| 312 | + /* multi-core data */ |
---|
336 | 313 | struct list_head queue_link; |
---|
| 314 | + s32 core_id; |
---|
337 | 315 | |
---|
338 | 316 | /* common per-device procfs */ |
---|
| 317 | + u32 disable; |
---|
339 | 318 | u32 timing_check; |
---|
340 | 319 | }; |
---|
341 | | - |
---|
342 | | -struct mpp_task; |
---|
343 | 320 | |
---|
344 | 321 | struct mpp_session { |
---|
345 | 322 | enum MPP_DEVICE_TYPE device_type; |
---|
.. | .. |
---|
379 | 356 | int (*wait_result)(struct mpp_session *session, |
---|
380 | 357 | struct mpp_task_msgs *msgs); |
---|
381 | 358 | void (*deinit)(struct mpp_session *session); |
---|
| 359 | + |
---|
| 360 | + /* max message count */ |
---|
| 361 | + int msgs_cnt; |
---|
| 362 | + struct list_head list_msgs; |
---|
| 363 | + struct list_head list_msgs_idle; |
---|
| 364 | + spinlock_t lock_msgs; |
---|
382 | 365 | }; |
---|
383 | 366 | |
---|
384 | 367 | /* task state in work thread */ |
---|
.. | .. |
---|
452 | 435 | /* hardware info for current task */ |
---|
453 | 436 | struct mpp_hw_info *hw_info; |
---|
454 | 437 | u32 task_index; |
---|
| 438 | + u32 task_id; |
---|
455 | 439 | u32 *reg; |
---|
456 | | - /* hw cycles */ |
---|
457 | | - u32 hw_cycles; |
---|
458 | 440 | /* event for session wait thread */ |
---|
459 | 441 | wait_queue_head_t wait; |
---|
| 442 | + |
---|
| 443 | + /* for multi-core */ |
---|
| 444 | + struct mpp_dev *mpp; |
---|
| 445 | + s32 core_id; |
---|
| 446 | + /* hw cycles */ |
---|
| 447 | + u32 hw_cycles; |
---|
460 | 448 | }; |
---|
461 | 449 | |
---|
462 | 450 | struct mpp_taskqueue { |
---|
.. | .. |
---|
473 | 461 | struct list_head session_detach; |
---|
474 | 462 | atomic_t detach_count; |
---|
475 | 463 | |
---|
| 464 | + atomic_t task_id; |
---|
476 | 465 | /* lock for pending list */ |
---|
477 | 466 | struct mutex pending_lock; |
---|
478 | 467 | struct list_head pending_list; |
---|
.. | .. |
---|
494 | 483 | */ |
---|
495 | 484 | u32 task_capacity; |
---|
496 | 485 | |
---|
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 | | - |
---|
| 486 | + /* multi-core task distribution */ |
---|
| 487 | + atomic_t reset_request; |
---|
| 488 | + struct mpp_dev *cores[MPP_MAX_CORE_NUM]; |
---|
| 489 | + unsigned long core_idle; |
---|
| 490 | + u32 core_id_max; |
---|
| 491 | + u32 core_count; |
---|
| 492 | + unsigned long dev_active_flags; |
---|
505 | 493 | }; |
---|
506 | 494 | |
---|
507 | 495 | struct mpp_reset_group { |
---|
.. | .. |
---|
639 | 627 | struct mpp_task *task); |
---|
640 | 628 | int mpp_task_dump_reg(struct mpp_dev *mpp, |
---|
641 | 629 | struct mpp_task *task); |
---|
642 | | -int mpp_task_dump_hw_reg(struct mpp_dev *mpp, |
---|
643 | | - struct mpp_task *task); |
---|
| 630 | +int mpp_task_dump_hw_reg(struct mpp_dev *mpp); |
---|
644 | 631 | void mpp_task_dump_timing(struct mpp_task *task, s64 time_diff); |
---|
| 632 | + |
---|
645 | 633 | void mpp_reg_show(struct mpp_dev *mpp, u32 offset); |
---|
| 634 | +void mpp_reg_show_range(struct mpp_dev *mpp, u32 start, u32 end); |
---|
| 635 | +void mpp_free_task(struct kref *ref); |
---|
646 | 636 | |
---|
647 | 637 | void mpp_session_deinit(struct mpp_session *session); |
---|
648 | 638 | void mpp_session_cleanup_detach(struct mpp_taskqueue *queue, |
---|
649 | 639 | struct kthread_work *work); |
---|
650 | 640 | |
---|
| 641 | +int mpp_taskqueue_pending_to_run(struct mpp_taskqueue *queue, struct mpp_task *task); |
---|
| 642 | + |
---|
651 | 643 | int mpp_dev_probe(struct mpp_dev *mpp, |
---|
652 | 644 | struct platform_device *pdev); |
---|
653 | 645 | int mpp_dev_remove(struct mpp_dev *mpp); |
---|
| 646 | +void mpp_dev_shutdown(struct platform_device *pdev); |
---|
654 | 647 | int mpp_dev_register_srv(struct mpp_dev *mpp, struct mpp_service *srv); |
---|
655 | 648 | |
---|
656 | 649 | int mpp_power_on(struct mpp_dev *mpp); |
---|
.. | .. |
---|
807 | 800 | return rockchip_pmu_idle_request(mpp->dev, idle); |
---|
808 | 801 | } |
---|
809 | 802 | |
---|
| 803 | +static inline struct mpp_dev * |
---|
| 804 | +mpp_get_task_used_device(const struct mpp_task *task, |
---|
| 805 | + const struct mpp_session *session) |
---|
| 806 | +{ |
---|
| 807 | + return task->mpp ? task->mpp : session->mpp; |
---|
| 808 | +} |
---|
| 809 | + |
---|
810 | 810 | #ifdef CONFIG_ROCKCHIP_MPP_PROC_FS |
---|
811 | 811 | struct proc_dir_entry * |
---|
812 | 812 | mpp_procfs_create_u32(const char *name, umode_t mode, |
---|
.. | .. |
---|
841 | 841 | extern struct platform_driver rockchip_iep2_driver; |
---|
842 | 842 | extern struct platform_driver rockchip_jpgdec_driver; |
---|
843 | 843 | extern struct platform_driver rockchip_rkvdec2_driver; |
---|
844 | | -extern struct platform_driver rockchip_vdpp_driver; |
---|
845 | 844 | extern struct platform_driver rockchip_rkvenc2_driver; |
---|
| 845 | +extern struct platform_driver rockchip_av1dec_driver; |
---|
| 846 | +extern struct platform_driver rockchip_av1_iommu_driver; |
---|
| 847 | + |
---|
| 848 | +extern int av1dec_driver_register(struct platform_driver *drv); |
---|
| 849 | +extern void av1dec_driver_unregister(struct platform_driver *drv); |
---|
| 850 | +extern struct bus_type av1dec_bus; |
---|
| 851 | +extern struct platform_driver rockchip_vdpp_driver; |
---|
846 | 852 | |
---|
847 | 853 | #endif |
---|