1 /* SPDX-License-Identifier: MIT */
2 #ifndef __NVKM_ACR_H__
3 #define __NVKM_ACR_H__
4 #define nvkm_acr(p) container_of((p), struct nvkm_acr, subdev)
5 #include <core/subdev.h>
6 #include <core/falcon.h>
7 
8 enum nvkm_acr_lsf_id {
9 	NVKM_ACR_LSF_PMU = 0,
10 	NVKM_ACR_LSF_GSPLITE = 1,
11 	NVKM_ACR_LSF_FECS = 2,
12 	NVKM_ACR_LSF_GPCCS = 3,
13 	NVKM_ACR_LSF_NVDEC = 4,
14 	NVKM_ACR_LSF_SEC2 = 7,
15 	NVKM_ACR_LSF_MINION = 10,
16 	NVKM_ACR_LSF_NUM
17 };
18 
19 static inline const char *
nvkm_acr_lsf_id(enum nvkm_acr_lsf_id id)20 nvkm_acr_lsf_id(enum nvkm_acr_lsf_id id)
21 {
22 	switch (id) {
23 	case NVKM_ACR_LSF_PMU    : return "pmu";
24 	case NVKM_ACR_LSF_GSPLITE: return "gsplite";
25 	case NVKM_ACR_LSF_FECS   : return "fecs";
26 	case NVKM_ACR_LSF_GPCCS  : return "gpccs";
27 	case NVKM_ACR_LSF_NVDEC  : return "nvdec";
28 	case NVKM_ACR_LSF_SEC2   : return "sec2";
29 	case NVKM_ACR_LSF_MINION : return "minion";
30 	default:
31 		return "unknown";
32 	}
33 }
34 
35 struct nvkm_acr {
36 	const struct nvkm_acr_func *func;
37 	struct nvkm_subdev subdev;
38 
39 	struct list_head hsfw;
40 	struct list_head lsfw, lsf;
41 
42 	u64 managed_falcons;
43 
44 	struct nvkm_memory *wpr;
45 	u64 wpr_start;
46 	u64 wpr_end;
47 	u64 shadow_start;
48 
49 	struct nvkm_memory *inst;
50 	struct nvkm_vmm *vmm;
51 
52 	bool done;
53 	struct nvkm_acr_lsf *rtos;
54 
55 	const struct firmware *wpr_fw;
56 	bool wpr_comp;
57 	u64 wpr_prev;
58 };
59 
60 bool nvkm_acr_managed_falcon(struct nvkm_device *, enum nvkm_acr_lsf_id);
61 int nvkm_acr_bootstrap_falcons(struct nvkm_device *, unsigned long mask);
62 
63 int gm200_acr_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_acr **);
64 int gm20b_acr_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_acr **);
65 int gp102_acr_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_acr **);
66 int gp108_acr_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_acr **);
67 int gp10b_acr_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_acr **);
68 int gv100_acr_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_acr **);
69 int tu102_acr_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_acr **);
70 int ga102_acr_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_acr **);
71 
72 struct nvkm_acr_lsfw {
73 	const struct nvkm_acr_lsf_func *func;
74 	struct nvkm_falcon *falcon;
75 	enum nvkm_acr_lsf_id id;
76 
77 	struct list_head head;
78 
79 	struct nvkm_blob img;
80 
81 	const struct firmware *sig;
82 
83 	bool secure_bootloader;
84 	u32 bootloader_size;
85 	u32 bootloader_imem_offset;
86 
87 	u32 app_size;
88 	u32 app_start_offset;
89 	u32 app_imem_entry;
90 	u32 app_resident_code_offset;
91 	u32 app_resident_code_size;
92 	u32 app_resident_data_offset;
93 	u32 app_resident_data_size;
94 	u32 app_imem_offset;
95 	u32 app_dmem_offset;
96 
97 	u32 ucode_size;
98 	u32 data_size;
99 
100 	u32 fuse_ver;
101 	u32 engine_id;
102 	u32 ucode_id;
103 	u32 sig_size;
104 	u32 sig_nr;
105 	u8 *sigs;
106 
107 	struct {
108 		u32 lsb;
109 		u32 img;
110 		u32 bld;
111 	} offset;
112 	u32 bl_data_size;
113 };
114 
115 struct nvkm_acr_lsf_func {
116 /* The (currently) map directly to LSB header flags. */
117 #define NVKM_ACR_LSF_LOAD_CODE_AT_0                                  0x00000001
118 #define NVKM_ACR_LSF_DMACTL_REQ_CTX                                  0x00000004
119 #define NVKM_ACR_LSF_FORCE_PRIV_LOAD                                 0x00000008
120 	u32 flags;
121 	u32 bl_entry;
122 	u32 bld_size;
123 	void (*bld_write)(struct nvkm_acr *, u32 bld, struct nvkm_acr_lsfw *);
124 	void (*bld_patch)(struct nvkm_acr *, u32 bld, s64 adjust);
125 	u64 bootstrap_falcons;
126 	int (*bootstrap_falcon)(struct nvkm_falcon *, enum nvkm_acr_lsf_id);
127 	int (*bootstrap_multiple_falcons)(struct nvkm_falcon *, u32 mask);
128 };
129 
130 int
131 nvkm_acr_lsfw_load_sig_image_desc(struct nvkm_subdev *, struct nvkm_falcon *,
132 				  enum nvkm_acr_lsf_id, const char *path,
133 				  int ver, const struct nvkm_acr_lsf_func *);
134 int
135 nvkm_acr_lsfw_load_sig_image_desc_v1(struct nvkm_subdev *, struct nvkm_falcon *,
136 				     enum nvkm_acr_lsf_id, const char *path,
137 				     int ver, const struct nvkm_acr_lsf_func *);
138 
139 int
140 nvkm_acr_lsfw_load_sig_image_desc_v2(struct nvkm_subdev *, struct nvkm_falcon *,
141 				     enum nvkm_acr_lsf_id, const char *path,
142 				     int ver, const struct nvkm_acr_lsf_func *);
143 
144 int
145 nvkm_acr_lsfw_load_bl_inst_data_sig(struct nvkm_subdev *, struct nvkm_falcon *,
146 				    enum nvkm_acr_lsf_id, const char *path,
147 				    int ver, const struct nvkm_acr_lsf_func *);
148 
149 int
150 nvkm_acr_lsfw_load_bl_sig_net(struct nvkm_subdev *, struct nvkm_falcon *,
151 				    enum nvkm_acr_lsf_id, const char *path,
152 				    int ver, const struct nvkm_acr_lsf_func *,
153 				    const void *, u32, const void *, u32);
154 #endif
155