131bef57fSBen Skeggs /* SPDX-License-Identifier: MIT */
231bef57fSBen Skeggs #ifndef __NVKM_ACR_H__
331bef57fSBen Skeggs #define __NVKM_ACR_H__
431bef57fSBen Skeggs #define nvkm_acr(p) container_of((p), struct nvkm_acr, subdev)
531bef57fSBen Skeggs #include <core/subdev.h>
622dcda45SBen Skeggs #include <core/falcon.h>
731bef57fSBen Skeggs
8c63fe2e7SBen Skeggs enum nvkm_acr_lsf_id {
9c63fe2e7SBen Skeggs NVKM_ACR_LSF_PMU = 0,
10c63fe2e7SBen Skeggs NVKM_ACR_LSF_GSPLITE = 1,
11c63fe2e7SBen Skeggs NVKM_ACR_LSF_FECS = 2,
12c63fe2e7SBen Skeggs NVKM_ACR_LSF_GPCCS = 3,
13c63fe2e7SBen Skeggs NVKM_ACR_LSF_NVDEC = 4,
14c63fe2e7SBen Skeggs NVKM_ACR_LSF_SEC2 = 7,
15c63fe2e7SBen Skeggs NVKM_ACR_LSF_MINION = 10,
1686ce2a71SBen Skeggs NVKM_ACR_LSF_NUM
17c63fe2e7SBen Skeggs };
18c63fe2e7SBen Skeggs
1986ce2a71SBen Skeggs static inline const char *
nvkm_acr_lsf_id(enum nvkm_acr_lsf_id id)2086ce2a71SBen Skeggs nvkm_acr_lsf_id(enum nvkm_acr_lsf_id id)
2186ce2a71SBen Skeggs {
2286ce2a71SBen Skeggs switch (id) {
2386ce2a71SBen Skeggs case NVKM_ACR_LSF_PMU : return "pmu";
2486ce2a71SBen Skeggs case NVKM_ACR_LSF_GSPLITE: return "gsplite";
2586ce2a71SBen Skeggs case NVKM_ACR_LSF_FECS : return "fecs";
2686ce2a71SBen Skeggs case NVKM_ACR_LSF_GPCCS : return "gpccs";
2786ce2a71SBen Skeggs case NVKM_ACR_LSF_NVDEC : return "nvdec";
2886ce2a71SBen Skeggs case NVKM_ACR_LSF_SEC2 : return "sec2";
2986ce2a71SBen Skeggs case NVKM_ACR_LSF_MINION : return "minion";
3086ce2a71SBen Skeggs default:
3186ce2a71SBen Skeggs return "unknown";
3286ce2a71SBen Skeggs }
3386ce2a71SBen Skeggs }
3486ce2a71SBen Skeggs
3531bef57fSBen Skeggs struct nvkm_acr {
3667e7c6cfSBen Skeggs const struct nvkm_acr_func *func;
3731bef57fSBen Skeggs struct nvkm_subdev subdev;
38c63fe2e7SBen Skeggs
392541626cSBen Skeggs struct list_head hsfw;
4086ce2a71SBen Skeggs struct list_head lsfw, lsf;
4122dcda45SBen Skeggs
42de088372SBen Skeggs u64 managed_falcons;
43de088372SBen Skeggs
4422dcda45SBen Skeggs struct nvkm_memory *wpr;
4522dcda45SBen Skeggs u64 wpr_start;
4622dcda45SBen Skeggs u64 wpr_end;
4722dcda45SBen Skeggs u64 shadow_start;
4822dcda45SBen Skeggs
4922dcda45SBen Skeggs struct nvkm_memory *inst;
5022dcda45SBen Skeggs struct nvkm_vmm *vmm;
5122dcda45SBen Skeggs
5222dcda45SBen Skeggs bool done;
53a9d90860SBen Skeggs struct nvkm_acr_lsf *rtos;
5422dcda45SBen Skeggs
5522dcda45SBen Skeggs const struct firmware *wpr_fw;
5622dcda45SBen Skeggs bool wpr_comp;
5722dcda45SBen Skeggs u64 wpr_prev;
5831bef57fSBen Skeggs };
5967e7c6cfSBen Skeggs
6022dcda45SBen Skeggs bool nvkm_acr_managed_falcon(struct nvkm_device *, enum nvkm_acr_lsf_id);
6186ce2a71SBen Skeggs int nvkm_acr_bootstrap_falcons(struct nvkm_device *, unsigned long mask);
6286ce2a71SBen Skeggs
63c288b4deSBen Skeggs int gm200_acr_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_acr **);
64c288b4deSBen Skeggs int gm20b_acr_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_acr **);
65c288b4deSBen Skeggs int gp102_acr_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_acr **);
66c288b4deSBen Skeggs int gp108_acr_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_acr **);
67c288b4deSBen Skeggs int gp10b_acr_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_acr **);
682541626cSBen Skeggs int gv100_acr_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_acr **);
69c288b4deSBen Skeggs int tu102_acr_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_acr **);
704b569dedSBen Skeggs int ga102_acr_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_acr **);
71c63fe2e7SBen Skeggs
72c63fe2e7SBen Skeggs struct nvkm_acr_lsfw {
73c63fe2e7SBen Skeggs const struct nvkm_acr_lsf_func *func;
74c63fe2e7SBen Skeggs struct nvkm_falcon *falcon;
75c63fe2e7SBen Skeggs enum nvkm_acr_lsf_id id;
76c63fe2e7SBen Skeggs
77c63fe2e7SBen Skeggs struct list_head head;
78c63fe2e7SBen Skeggs
79c63fe2e7SBen Skeggs struct nvkm_blob img;
80c63fe2e7SBen Skeggs
81c63fe2e7SBen Skeggs const struct firmware *sig;
82c63fe2e7SBen Skeggs
834b569dedSBen Skeggs bool secure_bootloader;
84c63fe2e7SBen Skeggs u32 bootloader_size;
85c63fe2e7SBen Skeggs u32 bootloader_imem_offset;
86c63fe2e7SBen Skeggs
87c63fe2e7SBen Skeggs u32 app_size;
88c63fe2e7SBen Skeggs u32 app_start_offset;
89c63fe2e7SBen Skeggs u32 app_imem_entry;
90c63fe2e7SBen Skeggs u32 app_resident_code_offset;
91c63fe2e7SBen Skeggs u32 app_resident_code_size;
92c63fe2e7SBen Skeggs u32 app_resident_data_offset;
93c63fe2e7SBen Skeggs u32 app_resident_data_size;
944b569dedSBen Skeggs u32 app_imem_offset;
954b569dedSBen Skeggs u32 app_dmem_offset;
96c63fe2e7SBen Skeggs
97c63fe2e7SBen Skeggs u32 ucode_size;
98c63fe2e7SBen Skeggs u32 data_size;
9922dcda45SBen Skeggs
1004b569dedSBen Skeggs u32 fuse_ver;
1014b569dedSBen Skeggs u32 engine_id;
1024b569dedSBen Skeggs u32 ucode_id;
1034b569dedSBen Skeggs u32 sig_size;
1044b569dedSBen Skeggs u32 sig_nr;
1054b569dedSBen Skeggs u8 *sigs;
1064b569dedSBen Skeggs
10722dcda45SBen Skeggs struct {
10822dcda45SBen Skeggs u32 lsb;
10922dcda45SBen Skeggs u32 img;
11022dcda45SBen Skeggs u32 bld;
11122dcda45SBen Skeggs } offset;
11222dcda45SBen Skeggs u32 bl_data_size;
113c63fe2e7SBen Skeggs };
114c63fe2e7SBen Skeggs
115c63fe2e7SBen Skeggs struct nvkm_acr_lsf_func {
11622dcda45SBen Skeggs /* The (currently) map directly to LSB header flags. */
11722dcda45SBen Skeggs #define NVKM_ACR_LSF_LOAD_CODE_AT_0 0x00000001
11822dcda45SBen Skeggs #define NVKM_ACR_LSF_DMACTL_REQ_CTX 0x00000004
11922dcda45SBen Skeggs #define NVKM_ACR_LSF_FORCE_PRIV_LOAD 0x00000008
12022dcda45SBen Skeggs u32 flags;
121*c4bdac75SBen Skeggs u32 bl_entry;
12222dcda45SBen Skeggs u32 bld_size;
12322dcda45SBen Skeggs void (*bld_write)(struct nvkm_acr *, u32 bld, struct nvkm_acr_lsfw *);
12422dcda45SBen Skeggs void (*bld_patch)(struct nvkm_acr *, u32 bld, s64 adjust);
125de088372SBen Skeggs u64 bootstrap_falcons;
12686ce2a71SBen Skeggs int (*bootstrap_falcon)(struct nvkm_falcon *, enum nvkm_acr_lsf_id);
12786ce2a71SBen Skeggs int (*bootstrap_multiple_falcons)(struct nvkm_falcon *, u32 mask);
128c63fe2e7SBen Skeggs };
129c63fe2e7SBen Skeggs
130c63fe2e7SBen Skeggs int
131c63fe2e7SBen Skeggs nvkm_acr_lsfw_load_sig_image_desc(struct nvkm_subdev *, struct nvkm_falcon *,
132c63fe2e7SBen Skeggs enum nvkm_acr_lsf_id, const char *path,
133c63fe2e7SBen Skeggs int ver, const struct nvkm_acr_lsf_func *);
134c63fe2e7SBen Skeggs int
135c63fe2e7SBen Skeggs nvkm_acr_lsfw_load_sig_image_desc_v1(struct nvkm_subdev *, struct nvkm_falcon *,
136c63fe2e7SBen Skeggs enum nvkm_acr_lsf_id, const char *path,
137c63fe2e7SBen Skeggs int ver, const struct nvkm_acr_lsf_func *);
1384b569dedSBen Skeggs
1394b569dedSBen Skeggs int
1404b569dedSBen Skeggs nvkm_acr_lsfw_load_sig_image_desc_v2(struct nvkm_subdev *, struct nvkm_falcon *,
1414b569dedSBen Skeggs enum nvkm_acr_lsf_id, const char *path,
1424b569dedSBen Skeggs int ver, const struct nvkm_acr_lsf_func *);
1434b569dedSBen Skeggs
144c63fe2e7SBen Skeggs int
145c63fe2e7SBen Skeggs nvkm_acr_lsfw_load_bl_inst_data_sig(struct nvkm_subdev *, struct nvkm_falcon *,
146c63fe2e7SBen Skeggs enum nvkm_acr_lsf_id, const char *path,
147c63fe2e7SBen Skeggs int ver, const struct nvkm_acr_lsf_func *);
148*c4bdac75SBen Skeggs
149*c4bdac75SBen Skeggs int
150*c4bdac75SBen Skeggs nvkm_acr_lsfw_load_bl_sig_net(struct nvkm_subdev *, struct nvkm_falcon *,
151*c4bdac75SBen Skeggs enum nvkm_acr_lsf_id, const char *path,
152*c4bdac75SBen Skeggs int ver, const struct nvkm_acr_lsf_func *,
153*c4bdac75SBen Skeggs const void *, u32, const void *, u32);
15431bef57fSBen Skeggs #endif
155