1 /*
2  * Copyright(c) 2017 Intel Corporation. All rights reserved.
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  *
6  * Author: Liam Girdwood <liam.r.girdwood@linux.intel.com>
7  */
8 
9 #ifndef __INCLUDE_UAPI_USER_MANIFEST_H__
10 #define __INCLUDE_UAPI_USER_MANIFEST_H__
11 
12 #include <stdint.h>
13 
14 /* start offset for base FW module */
15 #define SOF_MAN_ELF_TEXT_OFFSET		0x2000
16 
17 /* FW Extended Manifest Header id = $AE1 */
18 #define SOF_MAN_EXT_HEADER_MAGIC	0x31454124
19 
20 /* module type load type */
21 #define SOF_MAN_MOD_TYPE_BUILTIN	0
22 #define SOF_MAN_MOD_TYPE_MODULE		1
23 
24 struct sof_man_module_type {
25 	uint32_t load_type:4;	/* SOF_MAN_MOD_TYPE_ */
26 	uint32_t auto_start:1;
27 	uint32_t domain_ll:1;
28 	uint32_t domain_dp:1;
29 	uint32_t rsvd_:25;
30 };
31 
32 /* segment flags.type */
33 #define SOF_MAN_SEGMENT_TEXT		0
34 #define SOF_MAN_SEGMENT_RODATA		1
35 #define SOF_MAN_SEGMENT_DATA		1
36 #define SOF_MAN_SEGMENT_BSS		2
37 #define SOF_MAN_SEGMENT_EMPTY		15
38 
39 union sof_man_segment_flags {
40 	uint32_t ul;
41 	struct {
42 		uint32_t contents:1;
43 		uint32_t alloc:1;
44 		uint32_t load:1;
45 		uint32_t readonly:1;
46 		uint32_t code:1;
47 		uint32_t data:1;
48 		uint32_t _rsvd0:2;
49 		uint32_t type:4;	/* MAN_SEGMENT_ */
50 		uint32_t _rsvd1:4;
51 		uint32_t length:16;	/* of segment in pages */
52 	} r;
53 } __attribute__((packed));
54 
55 /*
56  * Module segment descriptor. Used by ROM - Immutable.
57  */
58 struct sof_man_segment_desc {
59 	union sof_man_segment_flags flags;
60 	uint32_t v_base_addr;
61 	uint32_t file_offset;
62 } __attribute__((packed));
63 
64 /*
65  * The firmware binary can be split into several modules.
66  */
67 
68 #define SOF_MAN_MOD_ID_LEN		4
69 #define SOF_MAN_MOD_NAME_LEN		8
70 #define SOF_MAN_MOD_SHA256_LEN		32
71 #define SOF_MAN_MOD_ID			{'$', 'A', 'M', 'E'}
72 
73 /*
74  * Each module has an entry in the FW header. Used by ROM - Immutable.
75  */
76 struct sof_man_module {
77 	uint8_t struct_id[SOF_MAN_MOD_ID_LEN];	/* SOF_MAN_MOD_ID */
78 	uint8_t name[SOF_MAN_MOD_NAME_LEN];
79 	uint8_t uuid[16];
80 	struct sof_man_module_type type;
81 	uint8_t hash[SOF_MAN_MOD_SHA256_LEN];
82 	uint32_t entry_point;
83 	uint16_t cfg_offset;
84 	uint16_t cfg_count;
85 	uint32_t affinity_mask;
86 	uint16_t instance_max_count;	/* max number of instances */
87 	uint16_t instance_bss_size;	/* instance (pages) */
88 	struct sof_man_segment_desc segment[3];
89 } __attribute__((packed));
90 
91 /*
92  * Each module has a configuration in the FW header. Used by ROM - Immutable.
93  */
94 struct sof_man_mod_config {
95 	uint32_t par[4];	/* module parameters */
96 	uint32_t is_pages;	/* actual size of instance .bss (pages) */
97 	uint32_t cps;		/* cycles per second */
98 	uint32_t ibs;		/* input buffer size (bytes) */
99 	uint32_t obs;		/* output buffer size (bytes) */
100 	uint32_t module_flags;	/* flags, reserved for future use */
101 	uint32_t cpc;		/* cycles per single run */
102 	uint32_t obls;		/* output block size, reserved for future use */
103 } __attribute__((packed));
104 
105 /*
106  * FW Manifest Header
107  */
108 
109 #define SOF_MAN_FW_HDR_FW_NAME_LEN	8
110 #define SOF_MAN_FW_HDR_ID		{'$', 'A', 'M', '1'}
111 #define SOF_MAN_FW_HDR_NAME		"ADSPFW"
112 #define SOF_MAN_FW_HDR_FLAGS		0x0
113 #define SOF_MAN_FW_HDR_FEATURES		0x1ff
114 
115 /*
116  * The firmware has a standard header that is checked by the ROM on firmware
117  * loading. preload_page_count is used by DMA code loader and is entire
118  * image size on CNL. i.e. CNL: total size of the binary’s .text and .rodata
119  * Used by ROM - Immutable.
120  */
121 struct sof_man_fw_header {
122 	uint8_t header_id[4];
123 	uint32_t header_len;
124 	uint8_t name[SOF_MAN_FW_HDR_FW_NAME_LEN];
125 	/* number of pages of preloaded image loaded by driver */
126 	uint32_t preload_page_count;
127 	uint32_t fw_image_flags;
128 	uint32_t feature_mask;
129 	uint16_t major_version;
130 	uint16_t minor_version;
131 	uint16_t hotfix_version;
132 	uint16_t build_version;
133 	uint32_t num_module_entries;
134 	uint32_t hw_buf_base_addr;
135 	uint32_t hw_buf_length;
136 	/* target address for binary loading as offset in IMR
137 	 * must be == base offset
138 	 */
139 	uint32_t load_offset;
140 } __attribute__((packed));
141 
142 /*
143  * Firmware manifest descriptor. This can contain N modules and N module
144  * configs. Used by ROM - Immutable.
145  */
146 struct sof_man_fw_desc {
147 	struct sof_man_fw_header header;
148 
149 	/* Warning - hack for module arrays. For some unknown reason the we
150 	 * have a variable size array of struct man_module followed by a
151 	 * variable size array of struct mod_config. These should have been
152 	 * merged into a variable array of a parent structure. We have to hack
153 	 * around this in many places....
154 	 *
155 	 * struct sof_man_module man_module[];
156 	 * struct sof_man_mod_config mod_config[];
157 	 */
158 
159 } __attribute__((packed));
160 
161 /*
162  * Component Descriptor. Used by ROM - Immutable.
163  */
164 struct sof_man_component_desc {
165 	uint32_t reserved[2];	/* all 0 */
166 	uint32_t version;
167 	uint8_t hash[SOF_MAN_MOD_SHA256_LEN];
168 	uint32_t base_offset;
169 	uint32_t limit_offset;
170 	uint32_t attributes[4];
171 } __attribute__((packed));
172 
173 /*
174  * Audio DSP extended metadata. Used by ROM - Immutable.
175  */
176 struct sof_man_adsp_meta_file_ext {
177 	uint32_t ext_type;	/* always 17 for ADSP extension */
178 	uint32_t ext_len;
179 	uint32_t imr_type;
180 	uint8_t reserved[16];	/* all 0 */
181 	struct sof_man_component_desc comp_desc[1];
182 } __attribute__((packed));
183 
184 /*
185  * Module Manifest for rimage module metadata. Not used by ROM.
186  */
187 struct sof_man_module_manifest {
188 	struct sof_man_module module;
189 	uint32_t text_size;
190 };
191 
192 /*
193  * Module offset in manifest.
194  */
195 #define SOF_MAN_MODULE_OFFSET(index) \
196 	(sizeof(struct sof_man_fw_header) + \
197 		(index) * sizeof(struct sof_man_module))
198 
199 #endif
200