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 	const struct nvkm_subdev *owner;
20 	const char *name;
21 	u32 addr;
22 
23 	struct mutex mutex;
24 	struct mutex dmem_mutex;
25 	bool oneinit;
26 
27 	const struct nvkm_subdev *user;
28 
29 	u8 version;
30 	u8 secret;
31 	bool debug;
32 
33 	struct nvkm_memory *core;
34 	bool external;
35 
36 	struct {
37 		u32 limit;
38 		u32 *data;
39 		u32  size;
40 		u8 ports;
41 	} code;
42 
43 	struct {
44 		u32 limit;
45 		u32 *data;
46 		u32  size;
47 		u8 ports;
48 	} data;
49 
50 	struct nvkm_engine engine;
51 };
52 
53 int nvkm_falcon_get(struct nvkm_falcon *, const struct nvkm_subdev *);
54 void nvkm_falcon_put(struct nvkm_falcon *, const struct nvkm_subdev *);
55 
56 int nvkm_falcon_new_(const struct nvkm_falcon_func *, struct nvkm_device *,
57 		     enum nvkm_subdev_type, int inst, bool enable, u32 addr, struct nvkm_engine **);
58 
59 struct nvkm_falcon_func {
60 	struct {
61 		u32 *data;
62 		u32  size;
63 	} code;
64 	struct {
65 		u32 *data;
66 		u32  size;
67 	} data;
68 	void (*init)(struct nvkm_falcon *);
69 	void (*intr)(struct nvkm_falcon *, struct nvkm_fifo_chan *);
70 
71 	u32 debug;
72 	u32 fbif;
73 
74 	void (*load_imem)(struct nvkm_falcon *, void *, u32, u32, u16, u8, bool);
75 	void (*load_dmem)(struct nvkm_falcon *, void *, u32, u32, u8);
76 	void (*read_dmem)(struct nvkm_falcon *, u32, u32, u8, void *);
77 	u32 emem_addr;
78 	void (*bind_context)(struct nvkm_falcon *, struct nvkm_memory *);
79 	int (*wait_for_halt)(struct nvkm_falcon *, u32);
80 	int (*clear_interrupt)(struct nvkm_falcon *, u32);
81 	void (*set_start_addr)(struct nvkm_falcon *, u32 start_addr);
82 	void (*start)(struct nvkm_falcon *);
83 	int (*enable)(struct nvkm_falcon *falcon);
84 	void (*disable)(struct nvkm_falcon *falcon);
85 	int (*reset)(struct nvkm_falcon *);
86 
87 	struct {
88 		u32 head;
89 		u32 tail;
90 		u32 stride;
91 	} cmdq, msgq;
92 
93 	struct nvkm_sclass sclass[];
94 };
95 
96 static inline u32
97 nvkm_falcon_rd32(struct nvkm_falcon *falcon, u32 addr)
98 {
99 	return nvkm_rd32(falcon->owner->device, falcon->addr + addr);
100 }
101 
102 static inline void
103 nvkm_falcon_wr32(struct nvkm_falcon *falcon, u32 addr, u32 data)
104 {
105 	nvkm_wr32(falcon->owner->device, falcon->addr + addr, data);
106 }
107 
108 static inline u32
109 nvkm_falcon_mask(struct nvkm_falcon *falcon, u32 addr, u32 mask, u32 val)
110 {
111 	struct nvkm_device *device = falcon->owner->device;
112 
113 	return nvkm_mask(device, falcon->addr + addr, mask, val);
114 }
115 
116 void nvkm_falcon_load_imem(struct nvkm_falcon *, void *, u32, u32, u16, u8,
117 			   bool);
118 void nvkm_falcon_load_dmem(struct nvkm_falcon *, void *, u32, u32, u8);
119 void nvkm_falcon_read_dmem(struct nvkm_falcon *, u32, u32, u8, void *);
120 void nvkm_falcon_bind_context(struct nvkm_falcon *, struct nvkm_memory *);
121 void nvkm_falcon_set_start_addr(struct nvkm_falcon *, u32);
122 void nvkm_falcon_start(struct nvkm_falcon *);
123 int nvkm_falcon_wait_for_halt(struct nvkm_falcon *, u32);
124 int nvkm_falcon_clear_interrupt(struct nvkm_falcon *, u32);
125 int nvkm_falcon_enable(struct nvkm_falcon *);
126 void nvkm_falcon_disable(struct nvkm_falcon *);
127 int nvkm_falcon_reset(struct nvkm_falcon *);
128 #endif
129