1 /* SPDX-License-Identifier: MIT */
2 /*
3  * Copyright © 2019 Intel Corporation
4  */
5 
6 #ifndef _INTEL_UC_FW_ABI_H
7 #define _INTEL_UC_FW_ABI_H
8 
9 #include <linux/types.h>
10 #include <linux/build_bug.h>
11 
12 /**
13  * DOC: Firmware Layout
14  *
15  * The GuC/HuC firmware layout looks like this::
16  *
17  *      +======================================================================+
18  *      |  Firmware blob                                                       |
19  *      +===============+===============+============+============+============+
20  *      |  CSS header   |     uCode     |  RSA key   |  modulus   |  exponent  |
21  *      +===============+===============+============+============+============+
22  *       <-header size->                 <---header size continued ----------->
23  *       <--- size ----------------------------------------------------------->
24  *                                       <-key size->
25  *                                                    <-mod size->
26  *                                                                 <-exp size->
27  *
28  * The firmware may or may not have modulus key and exponent data. The header,
29  * uCode and RSA signature are must-have components that will be used by driver.
30  * Length of each components, which is all in dwords, can be found in header.
31  * In the case that modulus and exponent are not present in fw, a.k.a truncated
32  * image, the length value still appears in header.
33  *
34  * Driver will do some basic fw size validation based on the following rules:
35  *
36  * 1. Header, uCode and RSA are must-have components.
37  * 2. All firmware components, if they present, are in the sequence illustrated
38  *    in the layout table above.
39  * 3. Length info of each component can be found in header, in dwords.
40  * 4. Modulus and exponent key are not required by driver. They may not appear
41  *    in fw. So driver will load a truncated firmware in this case.
42  *
43  * The only difference between GuC and HuC firmwares is how the version
44  * information is saved.
45  */
46 
47 struct uc_css_header {
48 	u32 module_type;
49 	/*
50 	 * header_size includes all non-uCode bits, including css_header, rsa
51 	 * key, modulus key and exponent data.
52 	 */
53 	u32 header_size_dw;
54 	u32 header_version;
55 	u32 module_id;
56 	u32 module_vendor;
57 	u32 date;
58 #define CSS_DATE_DAY			(0xFF << 0)
59 #define CSS_DATE_MONTH			(0xFF << 8)
60 #define CSS_DATE_YEAR			(0xFFFF << 16)
61 	u32 size_dw; /* uCode plus header_size_dw */
62 	u32 key_size_dw;
63 	u32 modulus_size_dw;
64 	u32 exponent_size_dw;
65 	u32 time;
66 #define CSS_TIME_HOUR			(0xFF << 0)
67 #define CSS_DATE_MIN			(0xFF << 8)
68 #define CSS_DATE_SEC			(0xFFFF << 16)
69 	char username[8];
70 	char buildnumber[12];
71 	u32 sw_version;
72 #define CSS_SW_VERSION_GUC_MAJOR	(0xFF << 16)
73 #define CSS_SW_VERSION_GUC_MINOR	(0xFF << 8)
74 #define CSS_SW_VERSION_GUC_PATCH	(0xFF << 0)
75 #define CSS_SW_VERSION_HUC_MAJOR	(0xFFFF << 16)
76 #define CSS_SW_VERSION_HUC_MINOR	(0xFFFF << 0)
77 	u32 reserved[14];
78 	u32 header_info;
79 } __packed;
80 static_assert(sizeof(struct uc_css_header) == 128);
81 
82 #endif /* _INTEL_UC_FW_ABI_H */
83