xref: /linux/drivers/gpu/drm/nouveau/nvkm/falcon/ga100.c (revision 1e5b3968a57d7894d5f86a2ecb58fa057cb6f7b2)
1 /*
2  * Copyright 2021 Red Hat Inc.
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
17  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20  * OTHER DEALINGS IN THE SOFTWARE.
21  */
22 #include "priv.h"
23 
24 int
25 ga100_flcn_fw_signature(struct nvkm_falcon_fw *fw, u32 *src_base_src)
26 {
27 	struct nvkm_falcon *falcon = fw->falcon;
28 	struct nvkm_device *device = falcon->owner->device;
29 	u32 reg_fuse_version;
30 	int idx;
31 
32 	FLCN_DBG(falcon, "brom: %08x %08x", fw->engine_id, fw->ucode_id);
33 	FLCN_DBG(falcon, "fuse_version: %d", fw->fuse_ver);
34 
35 	if (fw->engine_id & 0x00000001) {
36 		reg_fuse_version = nvkm_rd32(device, 0x824140 + (fw->ucode_id - 1) * 4);
37 	} else
38 	if (fw->engine_id & 0x00000004) {
39 		reg_fuse_version = nvkm_rd32(device, 0x824100 + (fw->ucode_id - 1) * 4);
40 	} else
41 	if (fw->engine_id & 0x00000400) {
42 		reg_fuse_version = nvkm_rd32(device, 0x8241c0 + (fw->ucode_id - 1) * 4);
43 	} else {
44 		WARN_ON(1);
45 		return -ENOSYS;
46 	}
47 
48 	FLCN_DBG(falcon, "reg_fuse_version: %08x", reg_fuse_version);
49 	if (reg_fuse_version) {
50 		reg_fuse_version = fls(reg_fuse_version);
51 		FLCN_DBG(falcon, "reg_fuse_version: %d", reg_fuse_version);
52 
53 		if (WARN_ON(fw->fuse_ver < reg_fuse_version))
54 			return -EINVAL;
55 
56 		idx = fw->fuse_ver - reg_fuse_version;
57 	} else {
58 		idx = fw->sig_nr - 1;
59 	}
60 
61 	return idx;
62 }
63