1 /*
2 * Copyright (c) 2014, NVIDIA CORPORATION. All rights reserved.
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 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.
21 */
22
23 #ifndef __NVKM_SECBOOT_LS_UCODE_H__
24 #define __NVKM_SECBOOT_LS_UCODE_H__
25
26 #include <core/os.h>
27 #include <core/subdev.h>
28 #include <subdev/secboot.h>
29
30 struct nvkm_acr;
31
32 /**
33 * struct ls_ucode_img_desc - descriptor of firmware image
34 * @descriptor_size: size of this descriptor
35 * @image_size: size of the whole image
36 * @bootloader_start_offset: start offset of the bootloader in ucode image
37 * @bootloader_size: size of the bootloader
38 * @bootloader_imem_offset: start off set of the bootloader in IMEM
39 * @bootloader_entry_point: entry point of the bootloader in IMEM
40 * @app_start_offset: start offset of the LS firmware
41 * @app_size: size of the LS firmware's code and data
42 * @app_imem_offset: offset of the app in IMEM
43 * @app_imem_entry: entry point of the app in IMEM
44 * @app_dmem_offset: offset of the data in DMEM
45 * @app_resident_code_offset: offset of app code from app_start_offset
46 * @app_resident_code_size: size of the code
47 * @app_resident_data_offset: offset of data from app_start_offset
48 * @app_resident_data_size: size of data
49 *
50 * A firmware image contains the code, data, and bootloader of a given LS
51 * falcon in a single blob. This structure describes where everything is.
52 *
53 * This can be generated from a (bootloader, code, data) set if they have
54 * been loaded separately, or come directly from a file.
55 */
56 struct ls_ucode_img_desc {
57 u32 descriptor_size;
58 u32 image_size;
59 u32 tools_version;
60 u32 app_version;
61 char date[64];
62 u32 bootloader_start_offset;
63 u32 bootloader_size;
64 u32 bootloader_imem_offset;
65 u32 bootloader_entry_point;
66 u32 app_start_offset;
67 u32 app_size;
68 u32 app_imem_offset;
69 u32 app_imem_entry;
70 u32 app_dmem_offset;
71 u32 app_resident_code_offset;
72 u32 app_resident_code_size;
73 u32 app_resident_data_offset;
74 u32 app_resident_data_size;
75 u32 nb_overlays;
76 struct {u32 start; u32 size; } load_ovl[64];
77 u32 compressed;
78 };
79
80 /**
81 * struct ls_ucode_img - temporary storage for loaded LS firmwares
82 * @node: to link within lsf_ucode_mgr
83 * @falcon_id: ID of the falcon this LS firmware is for
84 * @ucode_desc: loaded or generated map of ucode_data
85 * @ucode_data: firmware payload (code and data)
86 * @ucode_size: size in bytes of data in ucode_data
87 * @ucode_off: offset of the ucode in ucode_data
88 * @sig: signature for this firmware
89 * @sig:size: size of the signature in bytes
90 *
91 * Preparing the WPR LS blob requires information about all the LS firmwares
92 * (size, etc) to be known. This structure contains all the data of one LS
93 * firmware.
94 */
95 struct ls_ucode_img {
96 struct list_head node;
97 enum nvkm_secboot_falcon falcon_id;
98
99 struct ls_ucode_img_desc ucode_desc;
100 u8 *ucode_data;
101 u32 ucode_size;
102 u32 ucode_off;
103
104 u8 *sig;
105 u32 sig_size;
106 };
107
108 /**
109 * struct fw_bin_header - header of firmware files
110 * @bin_magic: always 0x3b1d14f0
111 * @bin_ver: version of the bin format
112 * @bin_size: entire image size including this header
113 * @header_offset: offset of the firmware/bootloader header in the file
114 * @data_offset: offset of the firmware/bootloader payload in the file
115 * @data_size: size of the payload
116 *
117 * This header is located at the beginning of the HS firmware and HS bootloader
118 * files, to describe where the headers and data can be found.
119 */
120 struct fw_bin_header {
121 u32 bin_magic;
122 u32 bin_ver;
123 u32 bin_size;
124 u32 header_offset;
125 u32 data_offset;
126 u32 data_size;
127 };
128
129 /**
130 * struct fw_bl_desc - firmware bootloader descriptor
131 * @start_tag: starting tag of bootloader
132 * @desc_dmem_load_off: DMEM offset of flcn_bl_dmem_desc
133 * @code_off: offset of code section
134 * @code_size: size of code section
135 * @data_off: offset of data section
136 * @data_size: size of data section
137 *
138 * This structure is embedded in bootloader firmware files at to describe the
139 * IMEM and DMEM layout expected by the bootloader.
140 */
141 struct fw_bl_desc {
142 u32 start_tag;
143 u32 dmem_load_off;
144 u32 code_off;
145 u32 code_size;
146 u32 data_off;
147 u32 data_size;
148 };
149
150 int acr_ls_ucode_load_fecs(const struct nvkm_secboot *, int,
151 struct ls_ucode_img *);
152 int acr_ls_ucode_load_gpccs(const struct nvkm_secboot *, int,
153 struct ls_ucode_img *);
154 int acr_ls_ucode_load_pmu(const struct nvkm_secboot *, int,
155 struct ls_ucode_img *);
156 int acr_ls_pmu_post_run(const struct nvkm_acr *, const struct nvkm_secboot *);
157 int acr_ls_ucode_load_sec2(const struct nvkm_secboot *, int,
158 struct ls_ucode_img *);
159 int acr_ls_sec2_post_run(const struct nvkm_acr *, const struct nvkm_secboot *);
160
161 #endif