summaryrefstree
path: root/kernel/drivers/vision/npu/ncp_header.h
blob: 548ff2a39c598c57f070236082bca18e65cff8b7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
/*
 * ncp.h
 *
 *  Created on: 2017. 7. 18.
 *      Author: kilyeon.im
 */

#ifndef NCP_H_
#define NCP_H_

#define NCP_MAGIC1		0x0C0FFEE0
#define NCP_MAGIC2		0xC0DEC0DE

#define NCP_VERSION		9

/**
 * @brief an element of address vector table
 */
struct address_vector {
	/**
	 * @brief index in address vector table
	 * @details producer : compiler
	 * @n consumer : driver, firmware
	 * @n description : this index is required for partial update of address vector(0 ~ n)
	 */
	u32	index;
	/**
	 * @brief master address (KITT side)
	 * @details producer : compiler, driver
	 * @n consumer : driver, firmware
	 * @n description : device virtual address or offset.
	 * this address can point feature map, weight, golden etc.
	 * offset is provided by compiler in case of weight, feature map and golden.
	 * driver should replace this offset to device virtual address.
	 * offset value means the offset from start of ncp header.
	 */
	u32 	m_addr;
	/**
	 * @brief slave address (TURING side)
	 * @details producer : driver
	 * @n consumer : firmware
	 * @n description :
	 */
	u32 	s_addr;
	/**
	 * @brief size in byte
	 * @details producer : compiler
	 * @n consumer : driver
	 * @n description : io feature map and intermediate feature map should have not zero size
	 */
	u32 	size;
};

enum ncp_memory_type {
	MEMORY_TYPE_IN_FMAP, /* input feature map */
	MEMORY_TYPE_OT_FMAP, /* output feature map */
	MEMORY_TYPE_IM_FMAP, /* intermediate feature map */
	MEMORY_TYPE_OT_PIX0,
	MEMORY_TYPE_OT_PIX1,
	MEMORY_TYPE_OT_PIX2,
	MEMORY_TYPE_OT_PIX3,
	MEMORY_TYPE_WEIGHT,
	MEMORY_TYPE_WMASK,
	MEMORY_TYPE_LUT,
	MEMORY_TYPE_NCP,
	MEMORY_TYPE_GOLDEN,
	MEMORY_TYPE_CUCODE,
	MEMORY_TYPE_MAX
};

/**
 * @brief an element of memory vector table
 */
struct memory_vector {
	/**
	 * @brief memory type
	 * @details producer : compiler
	 * @n consumer : all
	 * @n description : feature map, weight, weight mask, lut, ncp body. bias is included to ncp body.
	 */
	u32 	type;
	/**
	 * @brief pixsel format
	 * @details producer : compiler
	 * @n consumer : driver
	 * @n description : required pixel format (FOUR CC)
	 */
	u32 	pixel_format;
	/**
	 * @brief pixel width
	 * @details producer : compiler
	 * @n consumer : all
	 * @n description :
	 */
	u32 	width;
	/**
	 * @brief pixel height
	 * @details producer : compiler
	 * @n consumer : all
	 * @n description :
	 */
	u32 	height;
	/**
	 * @brief row stride
	 * @details producer : compiler
	 * @n consumer : all
	 * @n description : this stride value can be input or output stride
	 */
	u32 	stride;
	/**
	 * @brief channel count
	 * @details producer : compiler
	 * @n consumer : all
	 * @n description :
	 */
	u32 	channels;
	/**
	 * @brief channel stride
	 * @details producer : compiler
	 * @n consumer : all
	 * @n description : this stride value can be input or output stride
	 */
	u32 	cstride;
	/**
	 * @brief address vector index
	 * @details producer : framework
	 * @n consumer : firmware
	 * @n description : index of array of struct address_vector
	 */
	u32 	address_vector_index;
};

enum group_type {
	GROUP_TYPE_THREAD,
	GROUP_TYPE_SLOT,
	GROUP_TYPE_DUMMY,
	GROUP_TYPE_END
};

enum group_status {
	GROUP_STATUS_STANDBY, /* not started yet */
	GROUP_STATUS_START, /* right before start */
	GROUP_STATUS_STOP, /* stopped on work */
	GROUP_STATUE_DONE, /* process done */
	GROUP_STATUS_END
};

enum group_flags {
	GROUP_FLAG_SKIP, /* this group should be skipped to process */
	GROUP_FLAG_NOTIFY, /* notify flag look forward to notifying a completion of group process by status update */
	GROUP_FLAG_COMPARE, /* this flag look forward to comparing between output and golden */
	GROUP_FLAG_LAST, /* last flag means last group in chunk it's contained */
	GROUP_FLAG_WFS, /* group have to wait for standby status(WFS) */
	GROUP_FLAG_END
};

/**
 * @brief an element of group vector table
 */
struct group_vector {
	/**
	 * @brief group index
	 * @details producer : compiler
	 * @n consumer : firmware
	 * @n description : this index should be increased monotone by one
	 * range : 0 <= index < ncp_header->group_vector_cnt
	 */
	u32 	index;
	/**
	 * @brief group type
	 * @details producer : compiler
	 * @n consumer : all
	 * @n description : thread, slot
	 */
	u32 	type;
	/**
	 * @brief the offset at start of chunk
	 * @details producer : compiler
	 * @n consumer : firmware
	 * @n description : group address = body + chunk offset + group offset
	 */
	u32 	offset;
	/**
	 * @brief the size of group
	 * @details producer : compiler
	 * @n consumer : firmware
	 * @n description :
	 */
	u32 	size;
	/**
	 * @brief the status of group
	 * @details producer : firmware
	 * @n consumer : driver
	 * @n description : this shows progress of group
	 */
	u32 	status;
	/**
	 * @brief flags
	 * @details producer : all
	 * @n consumer : firmware
	 * @n description : bit flag can be orred, each bit corresponds to each flag.
	 */
	u32 	flags;
	/**
	 * @brief process count
	 * @details producer : compiler
	 * @n consumer : firmware
	 * @n description : process count is used for repeatation of isa only
	 * if this value is zero then just be done one time.
	 */
	u32 	batch;
	/**
	 * @brief the index of chunk vector table
	 * @details producer : compiler
	 * @n consumer : firmware
	 * @n description : 0 <= index < ncp_header->chunk_vector_cnt
	 */
	u32 	chunk_index;
	/**
	 * @brief subgroups
	 * @details producer : compiler
	 * @n consumer : profiler
	 * @n description : total subgroup count in this group
	 */
	u32 	subgroups;
	/**
	 * @brief nbuffering
	 * @details producer : compiler
	 * @n consumer : profiler
	 * @n description : the number of bufferring
	 */
	u32 	nbufferring;
	/**
	 * @brief the offset of intrinsic set
	 * @details producer : compiler
	 * @n consumer : firmware
	 * @n description : instrinsic address =  body + chunk offset + group_offset + intrinsic offset
	 */
	u32 	intrinsic_offset;
	/**
	 * @brief the size of intrinsic set
	 * @details producer : compiler
	 * @n consumer : firmware
	 * @n description :
	 */
	u32 	intrinsic_size;
	/**
	 * @brief the offset of command set
	 * @details producer : compiler
	 * @n consumer : firmware
	 * @n description : isa address =  body + chunk offset + group_offset + isa offset
	 */
	u32 	isa_offset;
	/**
	 * @brief the size of command set
	 * @details producer : compiler
	 * @n consumer : firmware
	 * @n description :
	 */
	u32 	isa_size;
};

/**
 * @brief an element of chunk vector table
 */
struct chunk_vector {
	/**
	 * @brief the chunk index
	 * @details producer : compiler
	 * @n consumer : firmware
	 * @n description : 0 <= index < ncp_header->group_vector_cnt
	 */
	u32 	index;
	/**
	 * @brief the offset of chunk from start of group
	 * @details producer : compiler
	 * @n consumer : firmware
	 * @n description : the absolute address of chunk is caculated by ncp body offset + chunk offset
	 */
	u32 	offset;
	/**
	 * @brief the size of a chunk
	 * @details producer : compiler
	 * @n consumer : firmware
	 * @n description :
	 */
	u32 	size;
	/**
	 * @brief the count of group
	 * @details producer : compiler
	 * @n consumer : firmware
	 * @n description :
	 */
	u32	group_cnt;
};

/**
 * @brief an element of blob vector table
 */
struct blob_vector {
	/**
	 * @brief direction
	 * @details producer : compiler
	 * @n consumer : firmware
	 * @n description : 0 is the load(dram to sram), 1 is the store(sram to dram)
	 */
	u16	direction;
	/**
	 * @brief batch id
	 * @details producer : compiler
	 * @n consumer : firmware
	 * @n description : a transfer to bind several blobs which they can be processed together.
	 * this id should be monotonically increased.
	 */
	u16	batch_id;
	/**
	 * @brief subgroup id
	 * @details producer : compiler
	 * @n consumer : firmware
	 * @n description :
	 */
	u16	sgid;
	/**
	 * @brief mark
	 * @details producer : compiler
	 * @n consumer : firmware
	 * @n description :
	 */
	u16	mark;
	/**
	 * @brief offset for source
	 * @details producer : compiler
	 * @n consumer : firmware
	 * @n description : an absolute address can be worked out from the base address of vector plus offset.
	 * 16 bytes alignment, this value should be shifted right as 4 bits
	 */
	u32	src_offset;
	/**
	 * @brief memory vector index for source
	 * @details producer : compiler
	 * @n consumer : firmware
	 * @n description :
	 */
	u16	src_vector;
	/**
	 * @brief source wdith stride
	 * @details producer : compiler
	 * @n consumer : firmware
	 * @n description : 16 bytes alignment, this value should be shifted right as 4 bits
	 */
	u16	src_w_stride;
	/**
	 * @brief source channel stride
	 * @details producer : compiler
	 * @n consumer : firmware
	 * @n description : 16 bytes alignment, this value should be shifted right as 4 bits
	 */
	u32	src_c_stride;
	/**
	 * @brief source n stride
	 * @details producer : compiler
	 * @n consumer : firmware
	 * @n description : 16 bytes alignment, this value should be shifted right as 4 bits
	 */
	u32	src_n_stride;
	/**
	 * @brief offset for destination
	 * @details producer : compiler
	 * @n consumer : firmware
	 * @n description : an absolute address can be worked out from the base address of vector plus offset.
	 * 16 bytes alignment, this value should be shifted right as 4 bits
	 */
	u32	dst_offset;
	/**
	 * @brief memory vector index for destination
	 * @details producer : compiler
	 * @n consumer : firmware
	 * @n description :
	 */
	u16	dst_vector;
	/**
	 * @brief destination width stride
	 * @details producer : compiler
	 * @n consumer : firmware
	 * @n description : 16 bytes alignment, this value should be shifted right as 4 bits
	 */
	u16	dst_w_stride;
	/**
	 * @brief destination channel stride
	 * @details producer : compiler
	 * @n consumer : firmware
	 * @n description : 16 bytes alignment, this value should be shifted right as 4 bits
	 */
	u32	dst_c_stride;
	/**
	 * @brief destination n stride
	 * @details producer : compiler
	 * @n consumer : firmware
	 * @n description : 16 bytes alignment, this value should be shifted right as 4 bits
	 */
	u32	dst_n_stride;
	/**
	 * @brief n
	 * @details producer : compiler
	 * @n consumer : firmware
	 * @n description : n of nchw
	 */
	u16	n;
	/**
	 * @brief c
	 * @details producer : compiler
	 * @n consumer : firmware
	 * @n description : c of nchw
	 */
	u16	c;
	/**
	 * @brief h
	 * @details producer : compiler
	 * @n consumer : firmware
	 * @n description : h of nchw
	 */
	u16	h;
	/**
	 * @brief w
	 * @details producer : compiler
	 * @n consumer : firmware
	 * @n description : w of nchw
	 */
	u16	w;
};

/**
 * @brief ncp header to describe image structure
 */
struct ncp_header {
	/**
	 * @brief magic number at start
	 * @details producer : compiler
	 * @n consumer : all
	 * @n description : for detecting memory invasion
	 */
	u32 	magic_number1;
	/**
	 * @brief ncp header version
	 * @details producer : compiler
	 * @n consumer : all
	 * @n description : the format of version number is decimal
	 */
	u32 	hdr_version;
	/**
	 * @brief ncp header size
	 * @details producer : compiler & driver
	 * @n consumer : all
	 * @n description : total ncp header size in byte, this size includes address, memory, group, chunk vector
	 */
	u32 	hdr_size;
	/**
	 * @brief intrinsic version
	 * @details producer : compiler
	 * @n consumer : firmware
	 * @n description : firmware should check intrinsic version before doing ncp
	 */
	u32 	intrinsic_version;
	/**
	 * @brief network id
	 * @details producer : compiler
	 * @n consumer : all
	 * @n description : network id is a fixed number before
	 */
	u32 	net_id;
	/**
	 * @brief unique id
	 * @details producer : driver
	 * @n consumer : all
	 * @n description : a unique number is made by driver and reported to framework
	 */
	u32 	unique_id;
	/**
	 * @brief priority
	 * @details producer : framework
	 * @n consumer : firmware
	 * @n description : the process order
	 */
	u32 	priority;
	/**
	 * @brief flags
	 * @details producer : framework
	 * @n consumer : all
	 * @n description : debug flag, and son on
	 */
	u32 	flags;
	/**
	 * @brief period time
	 * @details producer : framework
	 * @n consumer : driver, firmware
	 * @n description : duty time for done in micro second
	 */
	u32 	period;
	/**
	 * @brief workload
	 * @details producer : compiler
	 * @n consumer : firmware
	 * @n description : computational complexity of operation in cycle
	 */
	u32 	workload;
	/**
	 * @brief address vector offset
	 * @details producer : compiler
	 * @n consumer : all
	 * @n description : address vector offset in byte
	 */
	u32 	address_vector_offset;
	/**
	 * @brief the count of address vector
	 * @details producer : compiler
	 * @n consumer : all
	 * @n description :
	 */
	u32 	address_vector_cnt;
	/**
	 * @brief memory vector offset
	 * @details producer : compiler
	 * @n consumer : all
	 * @n description : memory vector offset in byte
	 */
	u32 	memory_vector_offset;
	/**
	 * @brief the count of memory vector
	 * @details producer : compiler
	 * @n consumer : all
	 * @n description :
	 */
	u32 	memory_vector_cnt;
	/**
	 * @brief chunk vector offset
	 * @details producer : compiler
	 * @n consumer : all
	 * @n description : chunk vector offset in byte
	 */
	u32 	chunk_vector_offset;
	/**
	 * @brief the count of chunk vector
	 * @details producer : compiler
	 * @n consumer : all
	 * @n description :
	 */
	u32 	chunk_vector_cnt;
	/**
	 * @brief group vector offset
	 * @details producer : compiler
	 * @n consumer : all
	 * @n description : group vector offset in byte
	 */
	u32 	group_vector_offset;
	/**
	 * @brief the count of group vector
	 * @details producer : compiler
	 * @n consumer : all
	 * @n description :
	 */
	u32 	group_vector_cnt;
	/**
	 * @brief ncp body version
	 * @details producer : compiler
	 * @n consumer : driver, firmware
	 * @n description :
	 */
	u32 	body_version;
	/**
	 * @brief ncp body offset
	 * @details producer : compiler
	 * @n consumer : all
	 * @n description : ncp body offset in byte
	 */
	u32 	body_offset;
	/**
	 * @brief ncp body size
	 * @details producer : compiler
	 * @n consumer : all
	 * @n description : ncp body size in byte
	 */
	u32 	body_size;
	/**
	 * @brief blob vector offset
	 * @details producer : compiler
	 * @n consumer : all
	 * @n description : blob vector offset in byte
	 */
	u32	blob_vector_offset;
	/**
	 * @brief the count of blob vector
	 * @details producer : compiler
	 * @n consumer : all
	 * @n description :
	 */
	u32	blob_vector_cnt;
	/**
	 * @brief reserved field
	 * @details producer : compiler
	 * @n consumer : all
	 * @n description : compatibility for the future
	 */
	u32	reserved[10];
	/**
	 * @brief magic number
	 * @details producer : compiler
	 * @n consumer : all
	 * @n description : correction for header version
	 */
	u32 	magic_number2;
};

#endif /* NCP_H_ */