forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-12-19 9370bb92b2d16684ee45cf24e879c93c509162da
kernel/drivers/video/rockchip/mpp/mpp_common.h
....@@ -22,7 +22,9 @@
2222 #include <linux/reset.h>
2323 #include <linux/irqreturn.h>
2424 #include <linux/poll.h>
25
+#include <linux/platform_device.h>
2526 #include <soc/rockchip/pm_domains.h>
27
+#include <uapi/linux/rk-mpp.h>
2628
2729 #define MHZ (1000 * 1000)
2830 #define MPP_WORK_TIMEOUT_DELAY (500)
....@@ -30,16 +32,12 @@
3032 #define MPP_MAX_MSG_NUM (16)
3133 #define MPP_MAX_REG_TRANS_NUM (60)
3234 #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)
4035
4136 /* grf mask for get value */
4237 #define MPP_GRF_VAL_MASK (0xFFFF)
38
+
39
+/* max 4 cores supported */
40
+#define MPP_MAX_CORE_NUM (4)
4341
4442 /**
4543 * Device type: classified by hardware feature
....@@ -48,16 +46,18 @@
4846 MPP_DEVICE_VDPU1 = 0, /* 0x00000001 */
4947 MPP_DEVICE_VDPU2 = 1, /* 0x00000002 */
5048 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 */
5251
5352 MPP_DEVICE_HEVC_DEC = 8, /* 0x00000100 */
5453 MPP_DEVICE_RKVDEC = 9, /* 0x00000200 */
5554 MPP_DEVICE_AVSPLUS_DEC = 12, /* 0x00001000 */
56
- MPP_DEVICE_JPGDEC = 13, /* 0x00002000 */
55
+ MPP_DEVICE_RKJPEGD = 13, /* 0x00002000 */
5756
5857 MPP_DEVICE_RKVENC = 16, /* 0x00010000 */
5958 MPP_DEVICE_VEPU1 = 17, /* 0x00020000 */
6059 MPP_DEVICE_VEPU2 = 18, /* 0x00040000 */
60
+ MPP_DEVICE_VEPU2_JPEG = 19, /* 0x00080000 */
6161 MPP_DEVICE_VEPU22 = 24, /* 0x01000000 */
6262
6363 MPP_DEVICE_IEP2 = 28, /* 0x10000000 */
....@@ -81,47 +81,10 @@
8181 MPP_DRIVER_IEP2,
8282 MPP_DRIVER_JPGDEC,
8383 MPP_DRIVER_RKVDEC2,
84
- MPP_DRIVER_VDPP,
8584 MPP_DRIVER_RKVENC2,
85
+ MPP_DRIVER_AV1DEC,
86
+ MPP_DRIVER_VDPP,
8687 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,
12588 };
12689
12790 enum MPP_CLOCK_MODE {
....@@ -181,33 +144,39 @@
181144 CODEC_INFO_FLAG_BUTT,
182145 };
183146
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;
192152
193153 /* struct use to collect task set and poll message */
194154 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
+
195168 u32 flags;
196169 u32 req_cnt;
197
- struct mpp_request reqs[MPP_MAX_MSG_NUM];
198170 u32 set_cnt;
199171 u32 poll_cnt;
172
+
173
+ struct mpp_request reqs[MPP_MAX_MSG_NUM];
174
+ struct mpp_request *poll_req;
200175 };
201176
202177 struct mpp_grf_info {
203178 u32 offset;
204179 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
-
211180 struct regmap *grf;
212181 };
213182
....@@ -289,9 +258,6 @@
289258 bool is_dup;
290259 };
291260
292
-struct mpp_dma_session;
293
-
294
-struct mpp_taskqueue;
295261
296262 struct mpp_dev {
297263 struct device *dev;
....@@ -311,13 +277,24 @@
311277 * Default 1 means normal hardware can only accept one task at once.
312278 */
313279 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;
314287
315288 int irq;
289
+ bool is_irq_startup;
316290 u32 irq_status;
317291
318292 void __iomem *reg_base;
319293 struct mpp_grf_info *grf_info;
320294 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;
321298
322299 atomic_t reset_request;
323300 atomic_t session_index;
....@@ -330,16 +307,16 @@
330307 struct mpp_taskqueue *queue;
331308 struct mpp_reset_group *reset_group;
332309 /* point to MPP Service */
333
- struct platform_device *pdev_srv;
334310 struct mpp_service *srv;
335311
312
+ /* multi-core data */
336313 struct list_head queue_link;
314
+ s32 core_id;
337315
338316 /* common per-device procfs */
317
+ u32 disable;
339318 u32 timing_check;
340319 };
341
-
342
-struct mpp_task;
343320
344321 struct mpp_session {
345322 enum MPP_DEVICE_TYPE device_type;
....@@ -379,6 +356,12 @@
379356 int (*wait_result)(struct mpp_session *session,
380357 struct mpp_task_msgs *msgs);
381358 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;
382365 };
383366
384367 /* task state in work thread */
....@@ -452,11 +435,16 @@
452435 /* hardware info for current task */
453436 struct mpp_hw_info *hw_info;
454437 u32 task_index;
438
+ u32 task_id;
455439 u32 *reg;
456
- /* hw cycles */
457
- u32 hw_cycles;
458440 /* event for session wait thread */
459441 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;
460448 };
461449
462450 struct mpp_taskqueue {
....@@ -473,6 +461,7 @@
473461 struct list_head session_detach;
474462 atomic_t detach_count;
475463
464
+ atomic_t task_id;
476465 /* lock for pending list */
477466 struct mutex pending_lock;
478467 struct list_head pending_list;
....@@ -494,14 +483,13 @@
494483 */
495484 u32 task_capacity;
496485
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;
505493 };
506494
507495 struct mpp_reset_group {
....@@ -639,18 +627,23 @@
639627 struct mpp_task *task);
640628 int mpp_task_dump_reg(struct mpp_dev *mpp,
641629 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);
644631 void mpp_task_dump_timing(struct mpp_task *task, s64 time_diff);
632
+
645633 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);
646636
647637 void mpp_session_deinit(struct mpp_session *session);
648638 void mpp_session_cleanup_detach(struct mpp_taskqueue *queue,
649639 struct kthread_work *work);
650640
641
+int mpp_taskqueue_pending_to_run(struct mpp_taskqueue *queue, struct mpp_task *task);
642
+
651643 int mpp_dev_probe(struct mpp_dev *mpp,
652644 struct platform_device *pdev);
653645 int mpp_dev_remove(struct mpp_dev *mpp);
646
+void mpp_dev_shutdown(struct platform_device *pdev);
654647 int mpp_dev_register_srv(struct mpp_dev *mpp, struct mpp_service *srv);
655648
656649 int mpp_power_on(struct mpp_dev *mpp);
....@@ -807,6 +800,13 @@
807800 return rockchip_pmu_idle_request(mpp->dev, idle);
808801 }
809802
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
+
810810 #ifdef CONFIG_ROCKCHIP_MPP_PROC_FS
811811 struct proc_dir_entry *
812812 mpp_procfs_create_u32(const char *name, umode_t mode,
....@@ -841,7 +841,13 @@
841841 extern struct platform_driver rockchip_iep2_driver;
842842 extern struct platform_driver rockchip_jpgdec_driver;
843843 extern struct platform_driver rockchip_rkvdec2_driver;
844
-extern struct platform_driver rockchip_vdpp_driver;
845844 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;
846852
847853 #endif