xref: /openbmc/linux/drivers/gpu/drm/nouveau/nvkm/nvfw/ls.c (revision 979ac5ef)
1 /*
2  * Copyright 2019 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 <core/subdev.h>
23 #include <nvfw/ls.h>
24 
25 static void
26 nvfw_ls_desc_head(struct nvkm_subdev *subdev,
27 		  const struct nvfw_ls_desc_head *hdr)
28 {
29 	char *date;
30 
31 	nvkm_debug(subdev, "lsUcodeImgDesc:\n");
32 	nvkm_debug(subdev, "\tdescriptorSize       : %d\n",
33 			   hdr->descriptor_size);
34 	nvkm_debug(subdev, "\timageSize            : %d\n", hdr->image_size);
35 	nvkm_debug(subdev, "\ttoolsVersion         : 0x%x\n",
36 			   hdr->tools_version);
37 	nvkm_debug(subdev, "\tappVersion           : 0x%x\n", hdr->app_version);
38 
39 	date = kstrndup(hdr->date, sizeof(hdr->date), GFP_KERNEL);
40 	nvkm_debug(subdev, "\tdate                 : %s\n", date);
41 	kfree(date);
42 
43 	nvkm_debug(subdev, "\tbootloaderStartOffset: 0x%x\n",
44 			   hdr->bootloader_start_offset);
45 	nvkm_debug(subdev, "\tbootloaderSize       : 0x%x\n",
46 			   hdr->bootloader_size);
47 	nvkm_debug(subdev, "\tbootloaderImemOffset : 0x%x\n",
48 			   hdr->bootloader_imem_offset);
49 	nvkm_debug(subdev, "\tbootloaderEntryPoint : 0x%x\n",
50 			   hdr->bootloader_entry_point);
51 
52 	nvkm_debug(subdev, "\tappStartOffset       : 0x%x\n",
53 			   hdr->app_start_offset);
54 	nvkm_debug(subdev, "\tappSize              : 0x%x\n", hdr->app_size);
55 	nvkm_debug(subdev, "\tappImemOffset        : 0x%x\n",
56 			   hdr->app_imem_offset);
57 	nvkm_debug(subdev, "\tappImemEntry         : 0x%x\n",
58 			   hdr->app_imem_entry);
59 	nvkm_debug(subdev, "\tappDmemOffset        : 0x%x\n",
60 			   hdr->app_dmem_offset);
61 	nvkm_debug(subdev, "\tappResidentCodeOffset: 0x%x\n",
62 			   hdr->app_resident_code_offset);
63 	nvkm_debug(subdev, "\tappResidentCodeSize  : 0x%x\n",
64 			   hdr->app_resident_code_size);
65 	nvkm_debug(subdev, "\tappResidentDataOffset: 0x%x\n",
66 			   hdr->app_resident_data_offset);
67 	nvkm_debug(subdev, "\tappResidentDataSize  : 0x%x\n",
68 			   hdr->app_resident_data_size);
69 }
70 
71 const struct nvfw_ls_desc *
72 nvfw_ls_desc(struct nvkm_subdev *subdev, const void *data)
73 {
74 	const struct nvfw_ls_desc *hdr = data;
75 	int i;
76 
77 	nvfw_ls_desc_head(subdev, &hdr->head);
78 
79 	nvkm_debug(subdev, "\tnbOverlays           : %d\n", hdr->nb_overlays);
80 	for (i = 0; i < ARRAY_SIZE(hdr->load_ovl); i++) {
81 		nvkm_debug(subdev, "\tloadOvl[%d]          : 0x%x %d\n", i,
82 			   hdr->load_ovl[i].start, hdr->load_ovl[i].size);
83 	}
84 	nvkm_debug(subdev, "\tcompressed           : %d\n", hdr->compressed);
85 
86 	return hdr;
87 }
88 
89 const struct nvfw_ls_desc_v1 *
90 nvfw_ls_desc_v1(struct nvkm_subdev *subdev, const void *data)
91 {
92 	const struct nvfw_ls_desc_v1 *hdr = data;
93 	int i;
94 
95 	nvfw_ls_desc_head(subdev, &hdr->head);
96 
97 	nvkm_debug(subdev, "\tnbImemOverlays       : %d\n",
98 			   hdr->nb_imem_overlays);
99 	nvkm_debug(subdev, "\tnbDmemOverlays       : %d\n",
100 			   hdr->nb_imem_overlays);
101 	for (i = 0; i < ARRAY_SIZE(hdr->load_ovl); i++) {
102 		nvkm_debug(subdev, "\tloadOvl[%2d]          : 0x%x %d\n", i,
103 			   hdr->load_ovl[i].start, hdr->load_ovl[i].size);
104 	}
105 	nvkm_debug(subdev, "\tcompressed           : %d\n", hdr->compressed);
106 
107 	return hdr;
108 }
109 
110 const struct nvfw_ls_desc_v2 *
111 nvfw_ls_desc_v2(struct nvkm_subdev *subdev, const void *data)
112 {
113 	const struct nvfw_ls_desc_v2 *hdr = data;
114 	char *date;
115 	int i;
116 
117 	nvkm_debug(subdev, "lsUcodeImgDesc:\n");
118 	nvkm_debug(subdev, "\tdescriptorSize       : %d\n", hdr->descriptor_size);
119 	nvkm_debug(subdev, "\timageSize            : %d\n", hdr->image_size);
120 	nvkm_debug(subdev, "\ttoolsVersion         : 0x%x\n", hdr->tools_version);
121 	nvkm_debug(subdev, "\tappVersion           : 0x%x\n", hdr->app_version);
122 
123 	date = kstrndup(hdr->date, sizeof(hdr->date), GFP_KERNEL);
124 	nvkm_debug(subdev, "\tdate                 : %s\n", date);
125 	kfree(date);
126 
127 	nvkm_debug(subdev, "\tsecureBootloader     : 0x%x\n", hdr->secure_bootloader);
128 	nvkm_debug(subdev, "\tbootloaderStartOffset: 0x%x\n", hdr->bootloader_start_offset);
129 	nvkm_debug(subdev, "\tbootloaderSize       : 0x%x\n", hdr->bootloader_size);
130 	nvkm_debug(subdev, "\tbootloaderImemOffset : 0x%x\n", hdr->bootloader_imem_offset);
131 	nvkm_debug(subdev, "\tbootloaderEntryPoint : 0x%x\n", hdr->bootloader_entry_point);
132 
133 	nvkm_debug(subdev, "\tappStartOffset       : 0x%x\n", hdr->app_start_offset);
134 	nvkm_debug(subdev, "\tappSize              : 0x%x\n", hdr->app_size);
135 	nvkm_debug(subdev, "\tappImemOffset        : 0x%x\n", hdr->app_imem_offset);
136 	nvkm_debug(subdev, "\tappImemEntry         : 0x%x\n", hdr->app_imem_entry);
137 	nvkm_debug(subdev, "\tappDmemOffset        : 0x%x\n", hdr->app_dmem_offset);
138 	nvkm_debug(subdev, "\tappResidentCodeOffset: 0x%x\n", hdr->app_resident_code_offset);
139 	nvkm_debug(subdev, "\tappResidentCodeSize  : 0x%x\n", hdr->app_resident_code_size);
140 	nvkm_debug(subdev, "\tappResidentDataOffset: 0x%x\n", hdr->app_resident_data_offset);
141 	nvkm_debug(subdev, "\tappResidentDataSize  : 0x%x\n", hdr->app_resident_data_size);
142 
143 	nvkm_debug(subdev, "\tnbImemOverlays       : %d\n", hdr->nb_imem_overlays);
144 	nvkm_debug(subdev, "\tnbDmemOverlays       : %d\n", hdr->nb_dmem_overlays);
145 	for (i = 0; i < ARRAY_SIZE(hdr->load_ovl); i++) {
146 		nvkm_debug(subdev, "\tloadOvl[%d]          : 0x%x %d\n", i,
147 			   hdr->load_ovl[i].start, hdr->load_ovl[i].size);
148 	}
149 
150 	return hdr;
151 }
152 
153 const struct nvfw_ls_hsbl_bin_hdr *
154 nvfw_ls_hsbl_bin_hdr(struct nvkm_subdev *subdev, const void *data)
155 {
156 	const struct nvfw_ls_hsbl_bin_hdr *hdr = data;
157 
158 	nvkm_debug(subdev, "lsHsblBinHdr:\n");
159 	nvkm_debug(subdev, "\tbinMagic         : 0x%08x\n", hdr->bin_magic);
160 	nvkm_debug(subdev, "\tbinVer           : %d\n", hdr->bin_ver);
161 	nvkm_debug(subdev, "\tbinSize          : %d\n", hdr->bin_size);
162 	nvkm_debug(subdev, "\theaderOffset     : 0x%x\n", hdr->header_offset);
163 	return hdr;
164 }
165 
166 const struct nvfw_ls_hsbl_hdr *
167 nvfw_ls_hsbl_hdr(struct nvkm_subdev *subdev, const void *data)
168 {
169 	const struct nvfw_ls_hsbl_hdr *hdr = data;
170 
171 	nvkm_debug(subdev, "lsHsblHdr:\n");
172 	nvkm_debug(subdev, "\tsigProdOffset    : 0x%x\n", hdr->sig_prod_offset);
173 	nvkm_debug(subdev, "\tsigProdSize      : 0x%x\n", hdr->sig_prod_size);
174 	nvkm_debug(subdev, "\tpatchLoc         : 0x%x\n", hdr->patch_loc);
175 	nvkm_debug(subdev, "\tpatchSig         : 0x%x\n", hdr->patch_sig);
176 	nvkm_debug(subdev, "\tmetadataOffset   : 0x%x\n", hdr->meta_data_offset);
177 	nvkm_debug(subdev, "\tmetadataSize     : 0x%x\n", hdr->meta_data_size);
178 	nvkm_debug(subdev, "\tnumSig           : 0x%x\n", hdr->num_sig);
179 	return hdr;
180 }
181