xref: /linux/drivers/gpu/drm/nouveau/nvkm/falcon/qmgr.h (revision 24bce201d79807b668bf9d9e0aca801c5c0d5f78)
1 /* SPDX-License-Identifier: MIT */
2 #ifndef __NVKM_FALCON_QMGR_H__
3 #define __NVKM_FALCON_QMGR_H__
4 #include <core/falcon.h>
5 
6 #define HDR_SIZE sizeof(struct nvfw_falcon_msg)
7 #define QUEUE_ALIGNMENT 4
8 /* max size of the messages we can receive */
9 #define MSG_BUF_SIZE 128
10 
11 /**
12  * struct nvkm_falcon_qmgr_seq - keep track of ongoing commands
13  *
14  * Every time a command is sent, a sequence is assigned to it so the
15  * corresponding message can be matched. Upon receiving the message, a callback
16  * can be called and/or a completion signaled.
17  *
18  * @id:		sequence ID
19  * @state:	current state
20  * @callback:	callback to call upon receiving matching message
21  * @completion:	completion to signal after callback is called
22  */
23 struct nvkm_falcon_qmgr_seq {
24 	u16 id;
25 	enum {
26 		SEQ_STATE_FREE = 0,
27 		SEQ_STATE_PENDING,
28 		SEQ_STATE_USED,
29 		SEQ_STATE_CANCELLED
30 	} state;
31 	bool async;
32 	nvkm_falcon_qmgr_callback callback;
33 	void *priv;
34 	struct completion done;
35 	int result;
36 };
37 
38 /*
39  * We can have an arbitrary number of sequences, but realistically we will
40  * probably not use that much simultaneously.
41  */
42 #define NVKM_FALCON_QMGR_SEQ_NUM 16
43 
44 struct nvkm_falcon_qmgr {
45 	struct nvkm_falcon *falcon;
46 
47 	struct {
48 		struct mutex mutex;
49 		struct nvkm_falcon_qmgr_seq id[NVKM_FALCON_QMGR_SEQ_NUM];
50 		unsigned long tbl[BITS_TO_LONGS(NVKM_FALCON_QMGR_SEQ_NUM)];
51 	} seq;
52 };
53 
54 struct nvkm_falcon_qmgr_seq *
55 nvkm_falcon_qmgr_seq_acquire(struct nvkm_falcon_qmgr *);
56 void nvkm_falcon_qmgr_seq_release(struct nvkm_falcon_qmgr *,
57 				  struct nvkm_falcon_qmgr_seq *);
58 
59 struct nvkm_falcon_cmdq {
60 	struct nvkm_falcon_qmgr *qmgr;
61 	const char *name;
62 	struct mutex mutex;
63 	struct completion ready;
64 
65 	u32 head_reg;
66 	u32 tail_reg;
67 	u32 offset;
68 	u32 size;
69 
70 	u32 position;
71 };
72 
73 struct nvkm_falcon_msgq {
74 	struct nvkm_falcon_qmgr *qmgr;
75 	const char *name;
76 	struct mutex mutex;
77 
78 	u32 head_reg;
79 	u32 tail_reg;
80 	u32 offset;
81 
82 	u32 position;
83 };
84 
85 #define FLCNQ_PRINTK(t,q,f,a...)                                               \
86        FLCN_PRINTK(t, (q)->qmgr->falcon, "%s: "f, (q)->name, ##a)
87 #define FLCNQ_DBG(q,f,a...) FLCNQ_PRINTK(debug, (q), f, ##a)
88 #define FLCNQ_ERR(q,f,a...) FLCNQ_PRINTK(error, (q), f, ##a)
89 #endif
90