xref: /linux/drivers/gpu/drm/nouveau/include/nvkm/core/falcon.h (revision 0ea5c948cb64bab5bc7a5516774eb8536f05aa0d)
1 #ifndef __NVKM_FALCON_H__
2 #define __NVKM_FALCON_H__
3 #include <core/firmware.h>
4 #include <engine/falcon.h>
5 
6 enum nvkm_falcon_mem {
7 	IMEM,
8 	DMEM,
9 	EMEM,
10 };
11 
12 static inline const char *
nvkm_falcon_mem(enum nvkm_falcon_mem mem)13 nvkm_falcon_mem(enum nvkm_falcon_mem mem)
14 {
15 	switch (mem) {
16 	case IMEM: return "imem";
17 	case DMEM: return "dmem";
18 	case EMEM: return "emem";
19 	default:
20 		WARN_ON(1);
21 		return "?mem";
22 	}
23 }
24 
25 struct nvkm_falcon_func_pio {
26 	int min;
27 	int max;
28 	void (*wr_init)(struct nvkm_falcon *, u8 port, bool sec, u32 mem_base);
29 	void (*wr)(struct nvkm_falcon *, u8 port, const u8 *img, int len, u16 tag);
30 	void (*rd_init)(struct nvkm_falcon *, u8 port, u32 mem_base);
31 	void (*rd)(struct nvkm_falcon *, u8 port, const u8 *img, int len);
32 };
33 
34 struct nvkm_falcon_func_dma {
35 	int (*init)(struct nvkm_falcon *, u64 dma_addr, int xfer_len,
36 		    enum nvkm_falcon_mem, bool sec, u32 *cmd);
37 	void (*xfer)(struct nvkm_falcon *, u32 mem_base, u32 dma_base, u32 cmd);
38 	bool (*done)(struct nvkm_falcon *);
39 };
40 
41 int nvkm_falcon_ctor(const struct nvkm_falcon_func *, struct nvkm_subdev *owner,
42 		     const char *name, u32 addr, struct nvkm_falcon *);
43 void nvkm_falcon_dtor(struct nvkm_falcon *);
44 int nvkm_falcon_reset(struct nvkm_falcon *);
45 int nvkm_falcon_pio_wr(struct nvkm_falcon *, const u8 *img, u32 img_base, u8 port,
46 		       enum nvkm_falcon_mem mem_type, u32 mem_base, int len, u16 tag, bool sec);
47 int nvkm_falcon_pio_rd(struct nvkm_falcon *, u8 port, enum nvkm_falcon_mem type, u32 mem_base,
48 		       const u8 *img, u32 img_base, int len);
49 int nvkm_falcon_dma_wr(struct nvkm_falcon *, const u8 *img, u64 dma_addr, u32 dma_base,
50 		       enum nvkm_falcon_mem mem_type, u32 mem_base, int len, bool sec);
51 bool nvkm_falcon_riscv_active(struct nvkm_falcon *);
52 void nvkm_falcon_intr_retrigger(struct nvkm_falcon *);
53 
54 int gm200_flcn_reset_wait_mem_scrubbing(struct nvkm_falcon *);
55 int gm200_flcn_disable(struct nvkm_falcon *);
56 int gm200_flcn_enable(struct nvkm_falcon *);
57 void gm200_flcn_bind_inst(struct nvkm_falcon *, int, u64);
58 int gm200_flcn_bind_stat(struct nvkm_falcon *, bool);
59 extern const struct nvkm_falcon_func_pio gm200_flcn_imem_pio;
60 extern const struct nvkm_falcon_func_pio gm200_flcn_dmem_pio;
61 void gm200_flcn_tracepc(struct nvkm_falcon *);
62 
63 int gp102_flcn_reset_eng(struct nvkm_falcon *);
64 extern const struct nvkm_falcon_func_pio gp102_flcn_emem_pio;
65 
66 bool tu102_flcn_riscv_active(struct nvkm_falcon *);
67 
68 void ga100_flcn_intr_retrigger(struct nvkm_falcon *);
69 
70 int ga102_flcn_select(struct nvkm_falcon *);
71 int ga102_flcn_reset_prep(struct nvkm_falcon *);
72 int ga102_flcn_reset_wait_mem_scrubbing(struct nvkm_falcon *);
73 extern const struct nvkm_falcon_func_dma ga102_flcn_dma;
74 bool ga102_flcn_riscv_active(struct nvkm_falcon *);
75 
76 void nvkm_falcon_v1_load_imem(struct nvkm_falcon *,
77 			      void *, u32, u32, u16, u8, bool);
78 void nvkm_falcon_v1_load_dmem(struct nvkm_falcon *, void *, u32, u32, u8);
79 void nvkm_falcon_v1_start(struct nvkm_falcon *);
80 
81 #define FLCN_PRINTK(f,l,p,fmt,a...) ({                                                          \
82 	if ((f)->owner->name != (f)->name)                                                      \
83 		nvkm_printk___((f)->owner, (f)->user, NV_DBG_##l, p, "%s:"fmt, (f)->name, ##a); \
84 	else                                                                                    \
85 		nvkm_printk___((f)->owner, (f)->user, NV_DBG_##l, p, fmt, ##a);                 \
86 })
87 #define FLCN_DBG(f,fmt,a...) FLCN_PRINTK((f), DEBUG, info, " "fmt"\n", ##a)
88 #define FLCN_ERR(f,fmt,a...) FLCN_PRINTK((f), ERROR, err, " "fmt"\n", ##a)
89 #define FLCN_ERRON(f,c,fmt,a...) \
90 	({ bool _cond = (c); _cond ? FLCN_ERR(f, fmt, ##a) : FLCN_DBG(f, fmt, ##a); _cond; })
91 
92 
93 struct nvkm_falcon_fw {
94 	const struct nvkm_falcon_fw_func {
95 		int (*signature)(struct nvkm_falcon_fw *, u32 *sig_base_src);
96 		int (*reset)(struct nvkm_falcon_fw *);
97 		int (*setup)(struct nvkm_falcon_fw *);
98 		int (*load)(struct nvkm_falcon_fw *);
99 		int (*load_bld)(struct nvkm_falcon_fw *);
100 		int (*boot)(struct nvkm_falcon_fw *,
101 			    u32 *mbox0, u32 *mbox1, u32 mbox0_ok, u32 irqsclr);
102 	} *func;
103 	struct nvkm_firmware fw;
104 
105 	u32 sig_base_prd;
106 	u32 sig_base_dbg;
107 	u32 sig_base_img;
108 	u32 sig_size;
109 	int sig_nr;
110 	u8 *sigs;
111 	u32 fuse_ver;
112 	u32 engine_id;
113 	u32 ucode_id;
114 
115 	u32 nmem_base_img;
116 	u32 nmem_base;
117 	u32 nmem_size;
118 
119 	u32 imem_base_img;
120 	u32 imem_base;
121 	u32 imem_size;
122 
123 	u32 dmem_base_img;
124 	u32 dmem_base;
125 	u32 dmem_size;
126 	u32 dmem_sign;
127 
128 	u8 *boot;
129 	u32 boot_size;
130 	u32 boot_addr;
131 
132 	struct nvkm_falcon *falcon;
133 	struct nvkm_memory *inst;
134 	struct nvkm_vmm *vmm;
135 	struct nvkm_vma *vma;
136 };
137 
138 int nvkm_falcon_fw_ctor(const struct nvkm_falcon_fw_func *, const char *name, struct nvkm_device *,
139 		        bool bl, const void *src, u32 len, struct nvkm_falcon *,
140 			struct nvkm_falcon_fw *);
141 int nvkm_falcon_fw_ctor_hs(const struct nvkm_falcon_fw_func *, const char *name,
142 			   struct nvkm_subdev *, const char *bl, const char *img, int ver,
143 			   struct nvkm_falcon *falcon, struct nvkm_falcon_fw *fw);
144 int nvkm_falcon_fw_ctor_hs_v2(const struct nvkm_falcon_fw_func *, const char *name,
145 			      struct nvkm_subdev *, const char *img, int ver, struct nvkm_falcon *,
146 			      struct nvkm_falcon_fw *);
147 int nvkm_falcon_fw_sign(struct nvkm_falcon_fw *, u32 sig_base_img, u32 sig_size, const u8 *sigs,
148 			int sig_nr_prd, u32 sig_base_prd, int sig_nr_dbg, u32 sig_base_dbg);
149 int nvkm_falcon_fw_patch(struct nvkm_falcon_fw *);
150 void nvkm_falcon_fw_dtor(struct nvkm_falcon_fw *);
151 int nvkm_falcon_fw_oneinit(struct nvkm_falcon_fw *, struct nvkm_falcon *, struct nvkm_vmm *,
152 			   struct nvkm_memory *inst);
153 int nvkm_falcon_fw_boot(struct nvkm_falcon_fw *, struct nvkm_subdev *user,
154 			bool release, u32 *pmbox0, u32 *pmbox1, u32 mbox0_ok, u32 irqsclr);
155 
156 extern const struct nvkm_falcon_fw_func gm200_flcn_fw;
157 int gm200_flcn_fw_signature(struct nvkm_falcon_fw *, u32 *);
158 int gm200_flcn_fw_reset(struct nvkm_falcon_fw *);
159 int gm200_flcn_fw_load(struct nvkm_falcon_fw *);
160 int gm200_flcn_fw_boot(struct nvkm_falcon_fw *, u32 *, u32 *, u32, u32);
161 
162 int ga100_flcn_fw_signature(struct nvkm_falcon_fw *, u32 *);
163 
164 extern const struct nvkm_falcon_fw_func ga102_flcn_fw;
165 int ga102_flcn_fw_load(struct nvkm_falcon_fw *);
166 int ga102_flcn_fw_boot(struct nvkm_falcon_fw *, u32 *, u32 *, u32, u32);
167 
168 #define FLCNFW_PRINTK(f,l,p,fmt,a...) FLCN_PRINTK((f)->falcon, l, p, "%s: "fmt, (f)->fw.name, ##a)
169 #define FLCNFW_DBG(f,fmt,a...) FLCNFW_PRINTK((f), DEBUG, info, fmt"\n", ##a)
170 #define FLCNFW_ERR(f,fmt,a...) FLCNFW_PRINTK((f), ERROR, err, fmt"\n", ##a)
171 
172 /**
173  * struct nvfw_falcon_msg - header for all messages
174  *
175  * @unit_id:	id of firmware process that sent the message
176  * @size:	total size of message
177  * @ctrl_flags:	control flags
178  * @seq_id:	used to match a message from its corresponding command
179  */
180 struct nvfw_falcon_msg {
181 	u8 unit_id;
182 	u8 size;
183 	u8 ctrl_flags;
184 	u8 seq_id;
185 };
186 
187 #define nvfw_falcon_cmd nvfw_falcon_msg
188 #define NV_FALCON_CMD_UNIT_ID_REWIND                                       0x00
189 
190 struct nvkm_falcon_qmgr;
191 int nvkm_falcon_qmgr_new(struct nvkm_falcon *, struct nvkm_falcon_qmgr **);
192 void nvkm_falcon_qmgr_del(struct nvkm_falcon_qmgr **);
193 
194 typedef int
195 (*nvkm_falcon_qmgr_callback)(void *priv, struct nvfw_falcon_msg *);
196 
197 struct nvkm_falcon_cmdq;
198 int nvkm_falcon_cmdq_new(struct nvkm_falcon_qmgr *, const char *name,
199 			 struct nvkm_falcon_cmdq **);
200 void nvkm_falcon_cmdq_del(struct nvkm_falcon_cmdq **);
201 void nvkm_falcon_cmdq_init(struct nvkm_falcon_cmdq *,
202 			   u32 index, u32 offset, u32 size);
203 void nvkm_falcon_cmdq_fini(struct nvkm_falcon_cmdq *);
204 int nvkm_falcon_cmdq_send(struct nvkm_falcon_cmdq *, struct nvfw_falcon_cmd *,
205 			  nvkm_falcon_qmgr_callback, void *priv,
206 			  unsigned long timeout_jiffies);
207 
208 struct nvkm_falcon_msgq;
209 int nvkm_falcon_msgq_new(struct nvkm_falcon_qmgr *, const char *name,
210 			 struct nvkm_falcon_msgq **);
211 void nvkm_falcon_msgq_del(struct nvkm_falcon_msgq **);
212 void nvkm_falcon_msgq_init(struct nvkm_falcon_msgq *,
213 			   u32 index, u32 offset, u32 size);
214 bool nvkm_falcon_msgq_empty(struct nvkm_falcon_msgq *);
215 int nvkm_falcon_msgq_recv_initmsg(struct nvkm_falcon_msgq *, void *, u32 size);
216 void nvkm_falcon_msgq_recv(struct nvkm_falcon_msgq *);
217 #endif
218