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