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 *
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, hsf;
40 	struct list_head lsfw, lsf;
41 
42 	struct nvkm_memory *wpr;
43 	u64 wpr_start;
44 	u64 wpr_end;
45 	u64 shadow_start;
46 
47 	struct nvkm_memory *inst;
48 	struct nvkm_vmm *vmm;
49 
50 	bool done;
51 
52 	const struct firmware *wpr_fw;
53 	bool wpr_comp;
54 	u64 wpr_prev;
55 };
56 
57 bool nvkm_acr_managed_falcon(struct nvkm_device *, enum nvkm_acr_lsf_id);
58 int nvkm_acr_bootstrap_falcons(struct nvkm_device *, unsigned long mask);
59 
60 int gm200_acr_new(struct nvkm_device *, int, struct nvkm_acr **);
61 int gm20b_acr_new(struct nvkm_device *, int, struct nvkm_acr **);
62 int gp102_acr_new(struct nvkm_device *, int, struct nvkm_acr **);
63 int gp108_acr_new(struct nvkm_device *, int, struct nvkm_acr **);
64 int gp10b_acr_new(struct nvkm_device *, int, struct nvkm_acr **);
65 int tu102_acr_new(struct nvkm_device *, int, struct nvkm_acr **);
66 
67 struct nvkm_acr_lsfw {
68 	const struct nvkm_acr_lsf_func *func;
69 	struct nvkm_falcon *falcon;
70 	enum nvkm_acr_lsf_id id;
71 
72 	struct list_head head;
73 
74 	struct nvkm_blob img;
75 
76 	const struct firmware *sig;
77 
78 	u32 bootloader_size;
79 	u32 bootloader_imem_offset;
80 
81 	u32 app_size;
82 	u32 app_start_offset;
83 	u32 app_imem_entry;
84 	u32 app_resident_code_offset;
85 	u32 app_resident_code_size;
86 	u32 app_resident_data_offset;
87 	u32 app_resident_data_size;
88 
89 	u32 ucode_size;
90 	u32 data_size;
91 
92 	struct {
93 		u32 lsb;
94 		u32 img;
95 		u32 bld;
96 	} offset;
97 	u32 bl_data_size;
98 };
99 
100 struct nvkm_acr_lsf_func {
101 /* The (currently) map directly to LSB header flags. */
102 #define NVKM_ACR_LSF_LOAD_CODE_AT_0                                  0x00000001
103 #define NVKM_ACR_LSF_DMACTL_REQ_CTX                                  0x00000004
104 #define NVKM_ACR_LSF_FORCE_PRIV_LOAD                                 0x00000008
105 	u32 flags;
106 	u32 bld_size;
107 	void (*bld_write)(struct nvkm_acr *, u32 bld, struct nvkm_acr_lsfw *);
108 	void (*bld_patch)(struct nvkm_acr *, u32 bld, s64 adjust);
109 	int (*boot)(struct nvkm_falcon *);
110 	int (*bootstrap_falcon)(struct nvkm_falcon *, enum nvkm_acr_lsf_id);
111 	int (*bootstrap_multiple_falcons)(struct nvkm_falcon *, u32 mask);
112 };
113 
114 int
115 nvkm_acr_lsfw_load_sig_image_desc(struct nvkm_subdev *, struct nvkm_falcon *,
116 				  enum nvkm_acr_lsf_id, const char *path,
117 				  int ver, const struct nvkm_acr_lsf_func *);
118 int
119 nvkm_acr_lsfw_load_sig_image_desc_v1(struct nvkm_subdev *, struct nvkm_falcon *,
120 				     enum nvkm_acr_lsf_id, const char *path,
121 				     int ver, const struct nvkm_acr_lsf_func *);
122 int
123 nvkm_acr_lsfw_load_bl_inst_data_sig(struct nvkm_subdev *, struct nvkm_falcon *,
124 				    enum nvkm_acr_lsf_id, const char *path,
125 				    int ver, const struct nvkm_acr_lsf_func *);
126 #endif
127