1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 /*
3  *  Copyright 2018-2021 Broadcom Inc. All rights reserved.
4  *
5  */
6 #ifndef MPI30_IMAGE_H
7 #define MPI30_IMAGE_H     1
8 struct mpi3_comp_image_version {
9 	__le16     build_num;
10 	__le16     customer_id;
11 	u8         phase_minor;
12 	u8         phase_major;
13 	u8         gen_minor;
14 	u8         gen_major;
15 };
16 
17 struct mpi3_hash_exclusion_format {
18 	__le32                     offset;
19 	__le32                     size;
20 };
21 
22 #define MPI3_IMAGE_HASH_EXCUSION_NUM                           (4)
23 struct mpi3_component_image_header {
24 	__le32                            signature0;
25 	__le32                            load_address;
26 	__le32                            data_size;
27 	__le32                            start_offset;
28 	__le32                            signature1;
29 	__le32                            flash_offset;
30 	__le32                            image_size;
31 	__le32                            version_string_offset;
32 	__le32                            build_date_string_offset;
33 	__le32                            build_time_string_offset;
34 	__le32                            environment_variable_offset;
35 	__le32                            application_specific;
36 	__le32                            signature2;
37 	__le32                            header_size;
38 	__le32                            crc;
39 	__le32                            flags;
40 	__le32                            secondary_flash_offset;
41 	__le32                            etp_offset;
42 	__le32                            etp_size;
43 	union mpi3_version_union             rmc_interface_version;
44 	union mpi3_version_union             etp_interface_version;
45 	struct mpi3_comp_image_version        component_image_version;
46 	struct mpi3_hash_exclusion_format     hash_exclusion[MPI3_IMAGE_HASH_EXCUSION_NUM];
47 	__le32                            next_image_header_offset;
48 	union mpi3_version_union             security_version;
49 	__le32                            reserved84[31];
50 };
51 
52 #define MPI3_IMAGE_HEADER_SIGNATURE0_MPI3                     (0xeb00003e)
53 #define MPI3_IMAGE_HEADER_LOAD_ADDRESS_INVALID                (0x00000000)
54 #define MPI3_IMAGE_HEADER_SIGNATURE1_APPLICATION              (0x20505041)
55 #define MPI3_IMAGE_HEADER_SIGNATURE1_FIRST_MUTABLE            (0x20434d46)
56 #define MPI3_IMAGE_HEADER_SIGNATURE1_BSP                      (0x20505342)
57 #define MPI3_IMAGE_HEADER_SIGNATURE1_ROM_BIOS                 (0x534f4942)
58 #define MPI3_IMAGE_HEADER_SIGNATURE1_HII_X64                  (0x4d494948)
59 #define MPI3_IMAGE_HEADER_SIGNATURE1_HII_ARM                  (0x41494948)
60 #define MPI3_IMAGE_HEADER_SIGNATURE1_CPLD                     (0x444c5043)
61 #define MPI3_IMAGE_HEADER_SIGNATURE1_SPD                      (0x20445053)
62 #define MPI3_IMAGE_HEADER_SIGNATURE1_GAS_GAUGE                (0x20534147)
63 #define MPI3_IMAGE_HEADER_SIGNATURE1_PBLP                     (0x504c4250)
64 #define MPI3_IMAGE_HEADER_SIGNATURE2_VALUE                    (0x50584546)
65 #define MPI3_IMAGE_HEADER_FLAGS_DEVICE_KEY_BASIS_MASK         (0x00000030)
66 #define MPI3_IMAGE_HEADER_FLAGS_DEVICE_KEY_BASIS_CDI          (0x00000000)
67 #define MPI3_IMAGE_HEADER_FLAGS_DEVICE_KEY_BASIS_DI           (0x00000010)
68 #define MPI3_IMAGE_HEADER_FLAGS_SIGNED_NVDATA                 (0x00000008)
69 #define MPI3_IMAGE_HEADER_FLAGS_REQUIRES_ACTIVATION           (0x00000004)
70 #define MPI3_IMAGE_HEADER_FLAGS_COMPRESSED                    (0x00000002)
71 #define MPI3_IMAGE_HEADER_FLAGS_FLASH                         (0x00000001)
72 #define MPI3_IMAGE_HEADER_SIGNATURE0_OFFSET                   (0x00)
73 #define MPI3_IMAGE_HEADER_LOAD_ADDRESS_OFFSET                 (0x04)
74 #define MPI3_IMAGE_HEADER_DATA_SIZE_OFFSET                    (0x08)
75 #define MPI3_IMAGE_HEADER_START_OFFSET_OFFSET                 (0x0c)
76 #define MPI3_IMAGE_HEADER_SIGNATURE1_OFFSET                   (0x10)
77 #define MPI3_IMAGE_HEADER_FLASH_OFFSET_OFFSET                 (0x14)
78 #define MPI3_IMAGE_HEADER_FLASH_SIZE_OFFSET                   (0x18)
79 #define MPI3_IMAGE_HEADER_VERSION_STRING_OFFSET_OFFSET        (0x1c)
80 #define MPI3_IMAGE_HEADER_BUILD_DATE_STRING_OFFSET_OFFSET     (0x20)
81 #define MPI3_IMAGE_HEADER_BUILD_TIME_OFFSET_OFFSET            (0x24)
82 #define MPI3_IMAGE_HEADER_ENVIROMENT_VAR_OFFSET_OFFSET        (0x28)
83 #define MPI3_IMAGE_HEADER_APPLICATION_SPECIFIC_OFFSET         (0x2c)
84 #define MPI3_IMAGE_HEADER_SIGNATURE2_OFFSET                   (0x30)
85 #define MPI3_IMAGE_HEADER_HEADER_SIZE_OFFSET                  (0x34)
86 #define MPI3_IMAGE_HEADER_CRC_OFFSET                          (0x38)
87 #define MPI3_IMAGE_HEADER_FLAGS_OFFSET                        (0x3c)
88 #define MPI3_IMAGE_HEADER_SECONDARY_FLASH_OFFSET_OFFSET       (0x40)
89 #define MPI3_IMAGE_HEADER_ETP_OFFSET_OFFSET                   (0x44)
90 #define MPI3_IMAGE_HEADER_ETP_SIZE_OFFSET                     (0x48)
91 #define MPI3_IMAGE_HEADER_RMC_INTERFACE_VER_OFFSET            (0x4c)
92 #define MPI3_IMAGE_HEADER_ETP_INTERFACE_VER_OFFSET            (0x50)
93 #define MPI3_IMAGE_HEADER_COMPONENT_IMAGE_VER_OFFSET          (0x54)
94 #define MPI3_IMAGE_HEADER_HASH_EXCLUSION_OFFSET               (0x5c)
95 #define MPI3_IMAGE_HEADER_NEXT_IMAGE_HEADER_OFFSET_OFFSET     (0x7c)
96 #define MPI3_IMAGE_HEADER_SIZE                                (0x100)
97 struct mpi3_extended_image_header {
98 	u8                                image_type;
99 	u8                                reserved01[3];
100 	__le32                            checksum;
101 	__le32                            image_size;
102 	__le32                            next_image_header_offset;
103 	__le32                            reserved10[4];
104 	__le32                            identify_string[8];
105 };
106 
107 #define MPI3_EXT_IMAGE_IMAGETYPE_OFFSET         (0x00)
108 #define MPI3_EXT_IMAGE_IMAGESIZE_OFFSET         (0x08)
109 #define MPI3_EXT_IMAGE_NEXTIMAGE_OFFSET         (0x0c)
110 #define MPI3_EXT_IMAGE_HEADER_SIZE              (0x40)
111 #define MPI3_EXT_IMAGE_TYPE_UNSPECIFIED             (0x00)
112 #define MPI3_EXT_IMAGE_TYPE_NVDATA                  (0x03)
113 #define MPI3_EXT_IMAGE_TYPE_SUPPORTED_DEVICES       (0x07)
114 #define MPI3_EXT_IMAGE_TYPE_ENCRYPTED_HASH          (0x09)
115 #define MPI3_EXT_IMAGE_TYPE_RDE                     (0x0a)
116 #define MPI3_EXT_IMAGE_TYPE_AUXILIARY_PROCESSOR     (0x0b)
117 #define MPI3_EXT_IMAGE_TYPE_MIN_PRODUCT_SPECIFIC    (0x80)
118 #define MPI3_EXT_IMAGE_TYPE_MAX_PRODUCT_SPECIFIC    (0xff)
119 struct mpi3_supported_device {
120 	__le16                     device_id;
121 	__le16                     vendor_id;
122 	__le16                     device_id_mask;
123 	__le16                     reserved06;
124 	u8                         low_pci_rev;
125 	u8                         high_pci_rev;
126 	__le16                     reserved0a;
127 	__le32                     reserved0c;
128 };
129 
130 #ifndef MPI3_SUPPORTED_DEVICE_MAX
131 #define MPI3_SUPPORTED_DEVICE_MAX                      (1)
132 #endif
133 struct mpi3_supported_devices_data {
134 	u8                         image_version;
135 	u8                         reserved01;
136 	u8                         num_devices;
137 	u8                         reserved03;
138 	__le32                     reserved04;
139 	struct mpi3_supported_device   supported_device[MPI3_SUPPORTED_DEVICE_MAX];
140 };
141 
142 #ifndef MPI3_ENCRYPTED_HASH_MAX
143 #define MPI3_ENCRYPTED_HASH_MAX                      (1)
144 #endif
145 struct mpi3_encrypted_hash_entry {
146 	u8                         hash_image_type;
147 	u8                         hash_algorithm;
148 	u8                         encryption_algorithm;
149 	u8                         reserved03;
150 	__le32                     reserved04;
151 	__le32                     encrypted_hash[MPI3_ENCRYPTED_HASH_MAX];
152 };
153 
154 #define MPI3_HASH_IMAGE_TYPE_KEY_WITH_SIGNATURE      (0x03)
155 #define MPI3_HASH_ALGORITHM_VERSION_MASK             (0xe0)
156 #define MPI3_HASH_ALGORITHM_VERSION_NONE             (0x00)
157 #define MPI3_HASH_ALGORITHM_VERSION_SHA1             (0x20)
158 #define MPI3_HASH_ALGORITHM_VERSION_SHA2             (0x40)
159 #define MPI3_HASH_ALGORITHM_VERSION_SHA3             (0x60)
160 #define MPI3_HASH_ALGORITHM_SIZE_MASK                (0x1f)
161 #define MPI3_HASH_ALGORITHM_SIZE_UNUSED              (0x00)
162 #define MPI3_HASH_ALGORITHM_SIZE_SHA256              (0x01)
163 #define MPI3_HASH_ALGORITHM_SIZE_SHA512              (0x02)
164 #define MPI3_ENCRYPTION_ALGORITHM_UNUSED             (0x00)
165 #define MPI3_ENCRYPTION_ALGORITHM_RSA256             (0x01)
166 #define MPI3_ENCRYPTION_ALGORITHM_RSA512             (0x02)
167 #define MPI3_ENCRYPTION_ALGORITHM_RSA1024            (0x03)
168 #define MPI3_ENCRYPTION_ALGORITHM_RSA2048            (0x04)
169 #define MPI3_ENCRYPTION_ALGORITHM_RSA4096            (0x05)
170 #define MPI3_ENCRYPTION_ALGORITHM_RSA3072            (0x06)
171 #ifndef MPI3_PUBLIC_KEY_MAX
172 #define MPI3_PUBLIC_KEY_MAX                          (1)
173 #endif
174 struct mpi3_encrypted_key_with_hash_entry {
175 	u8                         hash_image_type;
176 	u8                         hash_algorithm;
177 	u8                         encryption_algorithm;
178 	u8                         reserved03;
179 	__le32                     reserved04;
180 	__le32                     public_key[MPI3_PUBLIC_KEY_MAX];
181 	__le32                     encrypted_hash[MPI3_ENCRYPTED_HASH_MAX];
182 };
183 
184 #ifndef MPI3_ENCRYPTED_HASH_ENTRY_MAX
185 #define MPI3_ENCRYPTED_HASH_ENTRY_MAX               (1)
186 #endif
187 struct mpi3_encrypted_hash_data {
188 	u8                                  image_version;
189 	u8                                  num_hash;
190 	__le16                              reserved02;
191 	__le32                              reserved04;
192 	struct mpi3_encrypted_hash_entry        encrypted_hash_entry[MPI3_ENCRYPTED_HASH_ENTRY_MAX];
193 };
194 
195 #ifndef MPI3_AUX_PROC_DATA_MAX
196 #define MPI3_AUX_PROC_DATA_MAX               (1)
197 #endif
198 struct mpi3_aux_processor_data {
199 	u8                         boot_method;
200 	u8                         num_load_addr;
201 	u8                         reserved02;
202 	u8                         type;
203 	__le32                     version;
204 	__le32                     load_address[8];
205 	__le32                     reserved28[22];
206 	__le32                     aux_processor_data[MPI3_AUX_PROC_DATA_MAX];
207 };
208 
209 #define MPI3_AUX_PROC_DATA_OFFSET                                     (0x80)
210 #define MPI3_AUXPROCESSOR_BOOT_METHOD_MO_MSG                          (0x00)
211 #define MPI3_AUXPROCESSOR_BOOT_METHOD_MO_DOORBELL                     (0x01)
212 #define MPI3_AUXPROCESSOR_BOOT_METHOD_COMPONENT                       (0x02)
213 #define MPI3_AUXPROCESSOR_TYPE_ARM_A15                                (0x00)
214 #define MPI3_AUXPROCESSOR_TYPE_ARM_M0                                 (0x01)
215 #define MPI3_AUXPROCESSOR_TYPE_ARM_R4                                 (0x02)
216 #endif
217