1 /* SPDX-License-Identifier: MIT */
2 #ifndef __NVKM_FLCNEN_H__
3 #define __NVKM_FLCNEN_H__
4 #define nvkm_falcon(p) container_of((p), struct nvkm_falcon, engine)
5 #include <core/engine.h>
6 struct nvkm_fifo_chan;
7 
8 enum nvkm_falcon_dmaidx {
9 	FALCON_DMAIDX_UCODE		= 0,
10 	FALCON_DMAIDX_VIRT		= 1,
11 	FALCON_DMAIDX_PHYS_VID		= 2,
12 	FALCON_DMAIDX_PHYS_SYS_COH	= 3,
13 	FALCON_DMAIDX_PHYS_SYS_NCOH	= 4,
14 	FALCON_SEC2_DMAIDX_UCODE	= 6,
15 };
16 
17 struct nvkm_falcon {
18 	const struct nvkm_falcon_func *func;
19 	struct nvkm_subdev *owner;
20 	const char *name;
21 	u32 addr;
22 	u32 addr2;
23 
24 	struct mutex mutex;
25 	struct mutex dmem_mutex;
26 	bool oneinit;
27 
28 	struct nvkm_subdev *user;
29 
30 	u8 version;
31 	u8 secret;
32 	bool debug;
33 
34 	struct nvkm_memory *core;
35 	bool external;
36 
37 	struct {
38 		u32 limit;
39 		u32 *data;
40 		u32  size;
41 		u8 ports;
42 	} code;
43 
44 	struct {
45 		u32 limit;
46 		u32 *data;
47 		u32  size;
48 		u8 ports;
49 	} data;
50 
51 	struct nvkm_engine engine;
52 };
53 
54 int nvkm_falcon_get(struct nvkm_falcon *, struct nvkm_subdev *);
55 void nvkm_falcon_put(struct nvkm_falcon *, struct nvkm_subdev *);
56 
57 int nvkm_falcon_new_(const struct nvkm_falcon_func *, struct nvkm_device *,
58 		     enum nvkm_subdev_type, int inst, bool enable, u32 addr, struct nvkm_engine **);
59 
60 struct nvkm_falcon_func {
61 	int (*disable)(struct nvkm_falcon *);
62 	int (*enable)(struct nvkm_falcon *);
63 	int (*select)(struct nvkm_falcon *);
64 	u32 addr2;
65 	bool reset_pmc;
66 	int (*reset_eng)(struct nvkm_falcon *);
67 	int (*reset_prep)(struct nvkm_falcon *);
68 	int (*reset_wait_mem_scrubbing)(struct nvkm_falcon *);
69 
70 	u32 debug;
71 	void (*bind_inst)(struct nvkm_falcon *, int target, u64 addr);
72 	int (*bind_stat)(struct nvkm_falcon *, bool intr);
73 	bool bind_intr;
74 
75 	const struct nvkm_falcon_func_pio *imem_pio;
76 	const struct nvkm_falcon_func_dma *imem_dma;
77 
78 	const struct nvkm_falcon_func_pio *dmem_pio;
79 	const struct nvkm_falcon_func_dma *dmem_dma;
80 
81 	u32 emem_addr;
82 	const struct nvkm_falcon_func_pio *emem_pio;
83 
84 	struct {
85 		u32 head;
86 		u32 tail;
87 		u32 stride;
88 	} cmdq, msgq;
89 
90 	struct {
91 		u32 *data;
92 		u32  size;
93 	} code;
94 	struct {
95 		u32 *data;
96 		u32  size;
97 	} data;
98 	void (*init)(struct nvkm_falcon *);
99 	void (*intr)(struct nvkm_falcon *, struct nvkm_chan *);
100 
101 	void (*load_imem)(struct nvkm_falcon *, void *, u32, u32, u16, u8, bool);
102 	void (*load_dmem)(struct nvkm_falcon *, void *, u32, u32, u8);
103 	void (*start)(struct nvkm_falcon *);
104 
105 	struct nvkm_sclass sclass[];
106 };
107 
108 static inline u32
nvkm_falcon_rd32(struct nvkm_falcon * falcon,u32 addr)109 nvkm_falcon_rd32(struct nvkm_falcon *falcon, u32 addr)
110 {
111 	return nvkm_rd32(falcon->owner->device, falcon->addr + addr);
112 }
113 
114 static inline void
nvkm_falcon_wr32(struct nvkm_falcon * falcon,u32 addr,u32 data)115 nvkm_falcon_wr32(struct nvkm_falcon *falcon, u32 addr, u32 data)
116 {
117 	nvkm_wr32(falcon->owner->device, falcon->addr + addr, data);
118 }
119 
120 static inline u32
nvkm_falcon_mask(struct nvkm_falcon * falcon,u32 addr,u32 mask,u32 val)121 nvkm_falcon_mask(struct nvkm_falcon *falcon, u32 addr, u32 mask, u32 val)
122 {
123 	struct nvkm_device *device = falcon->owner->device;
124 
125 	return nvkm_mask(device, falcon->addr + addr, mask, val);
126 }
127 
128 void nvkm_falcon_load_imem(struct nvkm_falcon *, void *, u32, u32, u16, u8,
129 			   bool);
130 void nvkm_falcon_load_dmem(struct nvkm_falcon *, void *, u32, u32, u8);
131 void nvkm_falcon_start(struct nvkm_falcon *);
132 #endif
133