2 * Copyright (c) 2017, NVIDIA CORPORATION. All rights reserved.
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:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
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 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 * DEALINGS IN THE SOFTWARE.
27 #include <engine/falcon.h>
30 * hs_ucode_patch_signature() - patch HS blob with correct signature for
34 hs_ucode_patch_signature(const struct nvkm_falcon *falcon, void *acr_image,
37 struct fw_bin_header *hsbin_hdr = acr_image;
38 struct hsf_fw_header *fw_hdr = acr_image + hsbin_hdr->header_offset;
39 void *hs_data = acr_image + hsbin_hdr->data_offset;
42 u32 patch_loc, patch_sig;
45 * I had the brilliant idea to "improve" the binary format by
46 * removing this useless indirection. However to make NVIDIA files
47 * directly compatible, let's support both format.
50 patch_loc = fw_hdr->patch_loc;
51 patch_sig = fw_hdr->patch_sig;
53 patch_loc = *(u32 *)(acr_image + fw_hdr->patch_loc);
54 patch_sig = *(u32 *)(acr_image + fw_hdr->patch_sig);
57 /* Falcon in debug or production mode? */
59 sig = acr_image + fw_hdr->sig_dbg_offset;
60 sig_size = fw_hdr->sig_dbg_size;
62 sig = acr_image + fw_hdr->sig_prod_offset;
63 sig_size = fw_hdr->sig_prod_size;
67 memcpy(hs_data + patch_loc, sig + patch_sig, sig_size);
71 hs_ucode_load_blob(struct nvkm_subdev *subdev, const struct nvkm_falcon *falcon,
77 acr_image = nvkm_acr_load_firmware(subdev, fw, 0);
78 if (IS_ERR(acr_image))
81 /* detect the format to define how signature should be patched */
82 switch (((u32 *)acr_image)[0]) {
90 nvkm_error(subdev, "unknown header for HS blob %s\n", fw);
91 return ERR_PTR(-EINVAL);
94 hs_ucode_patch_signature(falcon, acr_image, new_format);