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