xref: /openbmc/linux/drivers/accel/ivpu/vpu_jsm_api.h (revision 5e68a0ca)
1 /* SPDX-License-Identifier: MIT */
2 /*
3  * Copyright (C) 2020-2023 Intel Corporation
4  */
5 
6 /**
7  * @file
8  * @brief JSM shared definitions
9  *
10  * @ingroup Jsm
11  * @brief JSM shared definitions
12  * @{
13  */
14 #ifndef VPU_JSM_API_H
15 #define VPU_JSM_API_H
16 
17 /*
18  * Major version changes that break backward compatibility
19  */
20 #define VPU_JSM_API_VER_MAJOR 2
21 
22 /*
23  * Minor version changes when API backward compatibility is preserved.
24  */
25 #define VPU_JSM_API_VER_MINOR 10
26 
27 /*
28  * API header changed (field names, documentation, formatting) but API itself has not been changed
29  */
30 #define VPU_JSM_API_VER_PATCH 1
31 
32 /*
33  * Index in the API version table
34  */
35 #define VPU_JSM_API_VER_INDEX 4
36 
37 /*
38  * Number of Priority Bands for Hardware Scheduling
39  * Bands: RealTime, Focus, Normal, Idle
40  */
41 #define VPU_HWS_NUM_PRIORITY_BANDS 4
42 
43 /* Max number of impacted contexts that can be dealt with the engine reset command */
44 #define VPU_MAX_ENGINE_RESET_IMPACTED_CONTEXTS 3
45 
46 /** Pack the API structures for now, once alignment issues are fixed this can be removed */
47 #pragma pack(push, 1)
48 
49 /*
50  * Engine indexes.
51  */
52 #define VPU_ENGINE_COMPUTE 0
53 #define VPU_ENGINE_COPY	   1
54 #define VPU_ENGINE_NB	   2
55 
56 /*
57  * VPU status values.
58  */
59 #define VPU_JSM_STATUS_SUCCESS				 0x0U
60 #define VPU_JSM_STATUS_PARSING_ERR			 0x1U
61 #define VPU_JSM_STATUS_PROCESSING_ERR			 0x2U
62 #define VPU_JSM_STATUS_PREEMPTED			 0x3U
63 #define VPU_JSM_STATUS_ABORTED				 0x4U
64 #define VPU_JSM_STATUS_USER_CTX_VIOL_ERR		 0x5U
65 #define VPU_JSM_STATUS_GLOBAL_CTX_VIOL_ERR		 0x6U
66 #define VPU_JSM_STATUS_MVNCI_WRONG_INPUT_FORMAT		 0x7U
67 #define VPU_JSM_STATUS_MVNCI_UNSUPPORTED_NETWORK_ELEMENT 0x8U
68 #define VPU_JSM_STATUS_MVNCI_INVALID_HANDLE		 0x9U
69 #define VPU_JSM_STATUS_MVNCI_OUT_OF_RESOURCES		 0xAU
70 #define VPU_JSM_STATUS_MVNCI_NOT_IMPLEMENTED		 0xBU
71 #define VPU_JSM_STATUS_MVNCI_INTERNAL_ERROR		 0xCU
72 /* Job status returned when the job was preempted mid-inference */
73 #define VPU_JSM_STATUS_PREEMPTED_MID_INFERENCE		 0xDU
74 
75 /*
76  * Host <-> VPU IPC channels.
77  * ASYNC commands use a high priority channel, other messages use low-priority ones.
78  */
79 #define VPU_IPC_CHAN_ASYNC_CMD 0
80 #define VPU_IPC_CHAN_GEN_CMD   10
81 #define VPU_IPC_CHAN_JOB_RET   11
82 
83 /*
84  * Job flags bit masks.
85  */
86 #define VPU_JOB_FLAGS_NULL_SUBMISSION_MASK 0x00000001
87 
88 /*
89  * Sizes of the reserved areas in jobs, in bytes.
90  */
91 #define VPU_JOB_RESERVED_BYTES	     16
92 /*
93  * Sizes of the reserved areas in job queues, in bytes.
94  */
95 #define VPU_JOB_QUEUE_RESERVED_BYTES 52
96 
97 /*
98  * Max length (including trailing NULL char) of trace entity name (e.g., the
99  * name of a logging destination or a loggable HW component).
100  */
101 #define VPU_TRACE_ENTITY_NAME_MAX_LEN 32
102 
103 /*
104  * Max length (including trailing NULL char) of a dyndbg command.
105  *
106  * NOTE: 112 is used so that the size of 'struct vpu_ipc_msg' in the JSM API is
107  * 128 bytes (multiple of 64 bytes, the cache line size).
108  */
109 #define VPU_DYNDBG_CMD_MAX_LEN 112
110 
111 /*
112  * Job format.
113  */
114 struct vpu_job_queue_entry {
115 	u64 batch_buf_addr; /**< Address of VPU commands batch buffer */
116 	u32 job_id;	  /**< Job ID */
117 	u32 flags; /**< Flags bit field, see VPU_JOB_FLAGS_* above */
118 	u64 root_page_table_addr; /**< Address of root page table to use for this job */
119 	u64 root_page_table_update_counter; /**< Page tables update events counter */
120 	u64 preemption_buffer_address; /**< Address of the preemption buffer to use for this job */
121 	u64 preemption_buffer_size; /**< Size of the preemption buffer to use for this job */
122 	u8 reserved[VPU_JOB_RESERVED_BYTES];
123 };
124 
125 /*
126  * Job queue control registers.
127  */
128 struct vpu_job_queue_header {
129 	u32 engine_idx;
130 	u32 head;
131 	u32 tail;
132 	u8 reserved[VPU_JOB_QUEUE_RESERVED_BYTES];
133 };
134 
135 /*
136  * Job queue format.
137  */
138 struct vpu_job_queue {
139 	struct vpu_job_queue_header header;
140 	struct vpu_job_queue_entry job[];
141 };
142 
143 /**
144  * Logging entity types.
145  *
146  * This enum defines the different types of entities involved in logging.
147  */
148 enum vpu_trace_entity_type {
149 	/** Logging destination (entity where logs can be stored / printed). */
150 	VPU_TRACE_ENTITY_TYPE_DESTINATION = 1,
151 	/** Loggable HW component (HW entity that can be logged). */
152 	VPU_TRACE_ENTITY_TYPE_HW_COMPONENT = 2,
153 };
154 
155 /*
156  * Host <-> VPU IPC messages types.
157  */
158 enum vpu_ipc_msg_type {
159 	VPU_JSM_MSG_UNKNOWN = 0xFFFFFFFF,
160 	/* IPC Host -> Device, Async commands */
161 	VPU_JSM_MSG_ASYNC_CMD = 0x1100,
162 	VPU_JSM_MSG_ENGINE_RESET = VPU_JSM_MSG_ASYNC_CMD,
163 	VPU_JSM_MSG_ENGINE_PREEMPT = 0x1101,
164 	VPU_JSM_MSG_REGISTER_DB = 0x1102,
165 	VPU_JSM_MSG_UNREGISTER_DB = 0x1103,
166 	VPU_JSM_MSG_QUERY_ENGINE_HB = 0x1104,
167 	VPU_JSM_MSG_GET_POWER_LEVEL_COUNT = 0x1105,
168 	VPU_JSM_MSG_GET_POWER_LEVEL = 0x1106,
169 	VPU_JSM_MSG_SET_POWER_LEVEL = 0x1107,
170 	/* @deprecated */
171 	VPU_JSM_MSG_METRIC_STREAMER_OPEN = 0x1108,
172 	/* @deprecated */
173 	VPU_JSM_MSG_METRIC_STREAMER_CLOSE = 0x1109,
174 	/** Configure logging (used to modify configuration passed in boot params). */
175 	VPU_JSM_MSG_TRACE_SET_CONFIG = 0x110a,
176 	/** Return current logging configuration. */
177 	VPU_JSM_MSG_TRACE_GET_CONFIG = 0x110b,
178 	/**
179 	 * Get masks of destinations and HW components supported by the firmware
180 	 * (may vary between HW generations and FW compile
181 	 * time configurations)
182 	 */
183 	VPU_JSM_MSG_TRACE_GET_CAPABILITY = 0x110c,
184 	/** Get the name of a destination or HW component. */
185 	VPU_JSM_MSG_TRACE_GET_NAME = 0x110d,
186 	/**
187 	 * Release resource associated with host ssid . All jobs that belong to the host_ssid
188 	 * aborted and removed from internal scheduling queues. All doorbells assigned
189 	 * to the host_ssid are unregistered and any internal FW resources belonging to
190 	 * the host_ssid are released.
191 	 */
192 	VPU_JSM_MSG_SSID_RELEASE = 0x110e,
193 	/**
194 	 * Start collecting metric data.
195 	 * @see vpu_jsm_metric_streamer_start
196 	 */
197 	VPU_JSM_MSG_METRIC_STREAMER_START = 0x110f,
198 	/**
199 	 * Stop collecting metric data. This command will return success if it is called
200 	 * for a metric stream that has already been stopped or was never started.
201 	 * @see vpu_jsm_metric_streamer_stop
202 	 */
203 	VPU_JSM_MSG_METRIC_STREAMER_STOP = 0x1110,
204 	/**
205 	 * Update current and next buffer for metric data collection. This command can
206 	 * also be used to request information about the number of collected samples
207 	 * and the amount of data written to the buffer.
208 	 * @see vpu_jsm_metric_streamer_update
209 	 */
210 	VPU_JSM_MSG_METRIC_STREAMER_UPDATE = 0x1111,
211 	/**
212 	 * Request description of selected metric groups and metric counters within
213 	 * each group. The VPU will write the description of groups and counters to
214 	 * the buffer specified in the command structure.
215 	 * @see vpu_jsm_metric_streamer_start
216 	 */
217 	VPU_JSM_MSG_METRIC_STREAMER_INFO = 0x1112,
218 	/** Control command: Priority band setup */
219 	VPU_JSM_MSG_SET_PRIORITY_BAND_SETUP = 0x1113,
220 	/** Control command: Create command queue */
221 	VPU_JSM_MSG_CREATE_CMD_QUEUE = 0x1114,
222 	/** Control command: Destroy command queue */
223 	VPU_JSM_MSG_DESTROY_CMD_QUEUE = 0x1115,
224 	/** Control command: Set context scheduling properties */
225 	VPU_JSM_MSG_SET_CONTEXT_SCHED_PROPERTIES = 0x1116,
226 	/*
227 	 * Register a doorbell to notify VPU of new work. The doorbell may later be
228 	 * deallocated or reassigned to another context.
229 	 */
230 	VPU_JSM_MSG_HWS_REGISTER_DB = 0x1117,
231 	/* IPC Host -> Device, General commands */
232 	VPU_JSM_MSG_GENERAL_CMD = 0x1200,
233 	VPU_JSM_MSG_BLOB_DEINIT = VPU_JSM_MSG_GENERAL_CMD,
234 	/**
235 	 * Control dyndbg behavior by executing a dyndbg command; equivalent to
236 	 * Linux command: `echo '<dyndbg_cmd>' > <debugfs>/dynamic_debug/control`.
237 	 */
238 	VPU_JSM_MSG_DYNDBG_CONTROL = 0x1201,
239 	/* IPC Device -> Host, Job completion */
240 	VPU_JSM_MSG_JOB_DONE = 0x2100,
241 	/* IPC Device -> Host, Async command completion */
242 	VPU_JSM_MSG_ASYNC_CMD_DONE = 0x2200,
243 	VPU_JSM_MSG_ENGINE_RESET_DONE = VPU_JSM_MSG_ASYNC_CMD_DONE,
244 	VPU_JSM_MSG_ENGINE_PREEMPT_DONE = 0x2201,
245 	VPU_JSM_MSG_REGISTER_DB_DONE = 0x2202,
246 	VPU_JSM_MSG_UNREGISTER_DB_DONE = 0x2203,
247 	VPU_JSM_MSG_QUERY_ENGINE_HB_DONE = 0x2204,
248 	VPU_JSM_MSG_GET_POWER_LEVEL_COUNT_DONE = 0x2205,
249 	VPU_JSM_MSG_GET_POWER_LEVEL_DONE = 0x2206,
250 	VPU_JSM_MSG_SET_POWER_LEVEL_DONE = 0x2207,
251 	/* @deprecated */
252 	VPU_JSM_MSG_METRIC_STREAMER_OPEN_DONE = 0x2208,
253 	/* @deprecated */
254 	VPU_JSM_MSG_METRIC_STREAMER_CLOSE_DONE = 0x2209,
255 	/** Response to VPU_JSM_MSG_TRACE_SET_CONFIG. */
256 	VPU_JSM_MSG_TRACE_SET_CONFIG_RSP = 0x220a,
257 	/** Response to VPU_JSM_MSG_TRACE_GET_CONFIG. */
258 	VPU_JSM_MSG_TRACE_GET_CONFIG_RSP = 0x220b,
259 	/** Response to VPU_JSM_MSG_TRACE_GET_CAPABILITY. */
260 	VPU_JSM_MSG_TRACE_GET_CAPABILITY_RSP = 0x220c,
261 	/** Response to VPU_JSM_MSG_TRACE_GET_NAME. */
262 	VPU_JSM_MSG_TRACE_GET_NAME_RSP = 0x220d,
263 	/** Response to VPU_JSM_MSG_SSID_RELEASE. */
264 	VPU_JSM_MSG_SSID_RELEASE_DONE = 0x220e,
265 	/**
266 	 * Response to VPU_JSM_MSG_METRIC_STREAMER_START.
267 	 * VPU will return an error result if metric collection cannot be started,
268 	 * e.g. when the specified metric mask is invalid.
269 	 * @see vpu_jsm_metric_streamer_done
270 	 */
271 	VPU_JSM_MSG_METRIC_STREAMER_START_DONE = 0x220f,
272 	/**
273 	 * Response to VPU_JSM_MSG_METRIC_STREAMER_STOP.
274 	 * Returns information about collected metric data.
275 	 * @see vpu_jsm_metric_streamer_done
276 	 */
277 	VPU_JSM_MSG_METRIC_STREAMER_STOP_DONE = 0x2210,
278 	/**
279 	 * Response to VPU_JSM_MSG_METRIC_STREAMER_UPDATE.
280 	 * Returns information about collected metric data.
281 	 * @see vpu_jsm_metric_streamer_done
282 	 */
283 	VPU_JSM_MSG_METRIC_STREAMER_UPDATE_DONE = 0x2211,
284 	/**
285 	 * Response to VPU_JSM_MSG_METRIC_STREAMER_INFO.
286 	 * Returns a description of the metric groups and metric counters.
287 	 * @see vpu_jsm_metric_streamer_done
288 	 */
289 	VPU_JSM_MSG_METRIC_STREAMER_INFO_DONE = 0x2212,
290 	/**
291 	 * Asynchronous event sent from the VPU to the host either when the current
292 	 * metric buffer is full or when the VPU has collected a multiple of
293 	 * @notify_sample_count samples as indicated through the start command
294 	 * (VPU_JSM_MSG_METRIC_STREAMER_START). Returns information about collected
295 	 * metric data.
296 	 * @see vpu_jsm_metric_streamer_done
297 	 */
298 	VPU_JSM_MSG_METRIC_STREAMER_NOTIFICATION = 0x2213,
299 	/** Response to control command: Priority band setup */
300 	VPU_JSM_MSG_SET_PRIORITY_BAND_SETUP_RSP = 0x2214,
301 	/** Response to control command: Create command queue */
302 	VPU_JSM_MSG_CREATE_CMD_QUEUE_RSP = 0x2215,
303 	/** Response to control command: Destroy command queue */
304 	VPU_JSM_MSG_DESTROY_CMD_QUEUE_RSP = 0x2216,
305 	/** Response to control command: Set context scheduling properties */
306 	VPU_JSM_MSG_SET_CONTEXT_SCHED_PROPERTIES_RSP = 0x2217,
307 	/* IPC Device -> Host, General command completion */
308 	VPU_JSM_MSG_GENERAL_CMD_DONE = 0x2300,
309 	VPU_JSM_MSG_BLOB_DEINIT_DONE = VPU_JSM_MSG_GENERAL_CMD_DONE,
310 	/** Response to VPU_JSM_MSG_DYNDBG_CONTROL. */
311 	VPU_JSM_MSG_DYNDBG_CONTROL_RSP = 0x2301,
312 };
313 
314 enum vpu_ipc_msg_status { VPU_JSM_MSG_FREE, VPU_JSM_MSG_ALLOCATED };
315 
316 /*
317  * Host <-> LRT IPC message payload definitions
318  */
319 struct vpu_ipc_msg_payload_engine_reset {
320 	/* Engine to be reset. */
321 	u32 engine_idx;
322 };
323 
324 struct vpu_ipc_msg_payload_engine_preempt {
325 	/* Engine to be preempted. */
326 	u32 engine_idx;
327 	/* ID of the preemption request. */
328 	u32 preempt_id;
329 };
330 
331 /*
332  * @brief Register doorbell command structure.
333  * This structure supports doorbell registration for only OS scheduling.
334  * @see VPU_JSM_MSG_REGISTER_DB
335  */
336 struct vpu_ipc_msg_payload_register_db {
337 	/* Index of the doorbell to register. */
338 	u32 db_idx;
339 	/* Virtual address in Global GTT pointing to the start of job queue. */
340 	u64 jobq_base;
341 	/* Size of the job queue in bytes. */
342 	u32 jobq_size;
343 	/* Host sub-stream ID for the context assigned to the doorbell. */
344 	u32 host_ssid;
345 };
346 
347 /**
348  * @brief Unregister doorbell command structure.
349  * Request structure to unregister a doorbell for both HW and OS scheduling.
350  * @see VPU_JSM_MSG_UNREGISTER_DB
351  */
352 struct vpu_ipc_msg_payload_unregister_db {
353 	/* Index of the doorbell to unregister. */
354 	u32 db_idx;
355 };
356 
357 struct vpu_ipc_msg_payload_query_engine_hb {
358 	/* Engine to return heartbeat value. */
359 	u32 engine_idx;
360 };
361 
362 struct vpu_ipc_msg_payload_power_level {
363 	/**
364 	 * Requested power level. The power level value is in the
365 	 * range [0, power_level_count-1] where power_level_count
366 	 * is the number of available power levels as returned by
367 	 * the get power level count command. A power level of 0
368 	 * corresponds to the maximum possible power level, while
369 	 * power_level_count-1 corresponds to the minimum possible
370 	 * power level. Values outside of this range are not
371 	 * considered to be valid.
372 	 */
373 	u32 power_level;
374 };
375 
376 struct vpu_ipc_msg_payload_ssid_release {
377 	/* Host sub-stream ID for the context to be released. */
378 	u32 host_ssid;
379 };
380 
381 /**
382  * @brief Metric streamer start command structure.
383  * This structure is also used with VPU_JSM_MSG_METRIC_STREAMER_INFO to request metric
384  * groups and metric counters description from the firmware.
385  * @see VPU_JSM_MSG_METRIC_STREAMER_START
386  * @see VPU_JSM_MSG_METRIC_STREAMER_INFO
387  */
388 struct vpu_jsm_metric_streamer_start {
389 	/**
390 	 * Bitmask to select the desired metric groups.
391 	 * A metric group can belong only to one metric streamer instance at a time.
392 	 * Since each metric streamer instance has a unique set of metric groups, it
393 	 * can also identify a metric streamer instance if more than one instance was
394 	 * started. If the VPU device does not support multiple metric streamer instances,
395 	 * then VPU_JSM_MSG_METRIC_STREAMER_START will return an error even if the second
396 	 * instance has different groups to the first.
397 	 */
398 	u64 metric_group_mask;
399 	/** Sampling rate in nanoseconds. */
400 	u64 sampling_rate;
401 	/**
402 	 * If > 0 the VPU will send a VPU_JSM_MSG_METRIC_STREAMER_NOTIFICATION message
403 	 * after every @notify_sample_count samples is collected or dropped by the VPU.
404 	 * If set to UINT_MAX the VPU will only generate a notification when the metric
405 	 * buffer is full. If set to 0 the VPU will never generate a notification.
406 	 */
407 	u32 notify_sample_count;
408 	u32 reserved_0;
409 	/**
410 	 * Address and size of the buffer where the VPU will write metric data. The
411 	 * VPU writes all counters from enabled metric groups one after another. If
412 	 * there is no space left to write data at the next sample period the VPU
413 	 * will switch to the next buffer (@see next_buffer_addr) and will optionally
414 	 * send a notification to the host driver if @notify_sample_count is non-zero.
415 	 * If @next_buffer_addr is NULL the VPU will stop collecting metric data.
416 	 */
417 	u64 buffer_addr;
418 	u64 buffer_size;
419 	/**
420 	 * Address and size of the next buffer to write metric data to after the initial
421 	 * buffer is full. If the address is NULL the VPU will stop collecting metric
422 	 * data.
423 	 */
424 	u64 next_buffer_addr;
425 	u64 next_buffer_size;
426 };
427 
428 static_assert(sizeof(struct vpu_jsm_metric_streamer_start) % 8 == 0,
429 	      "vpu_jsm_metric_streamer_start is misaligned");
430 
431 /**
432  * @brief Metric streamer stop command structure.
433  * @see VPU_JSM_MSG_METRIC_STREAMER_STOP
434  */
435 struct vpu_jsm_metric_streamer_stop {
436 	/** Bitmask to select the desired metric groups. */
437 	u64 metric_group_mask;
438 };
439 
440 static_assert(sizeof(struct vpu_jsm_metric_streamer_stop) % 8 == 0,
441 	      "vpu_jsm_metric_streamer_stop is misaligned");
442 
443 /**
444  * Provide VPU FW with buffers to write metric data.
445  * @see VPU_JSM_MSG_METRIC_STREAMER_UPDATE
446  */
447 struct vpu_jsm_metric_streamer_update {
448 	/** Metric group mask that identifies metric streamer instance. */
449 	u64 metric_group_mask;
450 	/**
451 	 * Address and size of the buffer where the VPU will write metric data. If
452 	 * the buffer address is 0 or same as the currently used buffer the VPU will
453 	 * continue writing metric data to the current buffer. In this case the
454 	 * buffer size is ignored and the size of the current buffer is unchanged.
455 	 * If the address is non-zero and differs from the current buffer address the
456 	 * VPU will immediately switch data collection to the new buffer.
457 	 */
458 	u64 buffer_addr;
459 	u64 buffer_size;
460 	/**
461 	 * Address and size of the next buffer to write metric data after the initial
462 	 * buffer is full. If the address is NULL the VPU will stop collecting metric
463 	 * data but will continue to record dropped samples.
464 	 *
465 	 * Note that there is a hazard possible if both buffer_addr and the next_buffer_addr
466 	 * are non-zero in same update request. It is the host's responsibility to ensure
467 	 * that both addresses make sense even if the VPU just switched to writing samples
468 	 * from the current to the next buffer.
469 	 */
470 	u64 next_buffer_addr;
471 	u64 next_buffer_size;
472 };
473 
474 static_assert(sizeof(struct vpu_jsm_metric_streamer_update) % 8 == 0,
475 	      "vpu_jsm_metric_streamer_update is misaligned");
476 
477 struct vpu_ipc_msg_payload_blob_deinit {
478 	/* 64-bit unique ID for the blob to be de-initialized. */
479 	u64 blob_id;
480 };
481 
482 struct vpu_ipc_msg_payload_job_done {
483 	/* Engine to which the job was submitted. */
484 	u32 engine_idx;
485 	/* Index of the doorbell to which the job was submitted */
486 	u32 db_idx;
487 	/* ID of the completed job */
488 	u32 job_id;
489 	/* Status of the completed job */
490 	u32 job_status;
491 	/* Host SSID */
492 	u32 host_ssid;
493 	/* Zero Padding */
494 	u32 reserved;
495 	/* Command queue id */
496 	u64 cmdq_id;
497 };
498 
499 struct vpu_jsm_engine_reset_context {
500 	/* Host SSID */
501 	u32 host_ssid;
502 	/* Zero Padding */
503 	u32 reserved;
504 	/* Command queue id */
505 	u64 cmdq_id;
506 	/* Flags: 0: cause of hang; 1: collateral damage of reset */
507 	u64 flags;
508 };
509 
510 struct vpu_ipc_msg_payload_engine_reset_done {
511 	/* Engine ordinal */
512 	u32 engine_idx;
513 	/* Number of impacted contexts */
514 	u32 num_impacted_contexts;
515 	/* Array of impacted command queue ids and their flags */
516 	struct vpu_jsm_engine_reset_context
517 		impacted_contexts[VPU_MAX_ENGINE_RESET_IMPACTED_CONTEXTS];
518 };
519 
520 struct vpu_ipc_msg_payload_engine_preempt_done {
521 	/* Engine preempted. */
522 	u32 engine_idx;
523 	/* ID of the preemption request. */
524 	u32 preempt_id;
525 };
526 
527 /**
528  * Response structure for register doorbell command for both OS
529  * and HW scheduling.
530  * @see VPU_JSM_MSG_REGISTER_DB
531  * @see VPU_JSM_MSG_HWS_REGISTER_DB
532  */
533 struct vpu_ipc_msg_payload_register_db_done {
534 	/* Index of the registered doorbell. */
535 	u32 db_idx;
536 };
537 
538 /**
539  * Response structure for unregister doorbell command for both OS
540  * and HW scheduling.
541  * @see VPU_JSM_MSG_UNREGISTER_DB
542  */
543 struct vpu_ipc_msg_payload_unregister_db_done {
544 	/* Index of the unregistered doorbell. */
545 	u32 db_idx;
546 };
547 
548 struct vpu_ipc_msg_payload_query_engine_hb_done {
549 	/* Engine returning heartbeat value. */
550 	u32 engine_idx;
551 	/* Heartbeat value. */
552 	u64 heartbeat;
553 };
554 
555 struct vpu_ipc_msg_payload_get_power_level_count_done {
556 	/**
557 	 * Number of supported power levels. The maximum possible
558 	 * value of power_level_count is 16 but this may vary across
559 	 * implementations.
560 	 */
561 	u32 power_level_count;
562 	/**
563 	 * Power consumption limit for each supported power level in
564 	 * [0-100%] range relative to power level 0.
565 	 */
566 	u8 power_limit[16];
567 };
568 
569 struct vpu_ipc_msg_payload_blob_deinit_done {
570 	/* 64-bit unique ID for the blob de-initialized. */
571 	u64 blob_id;
572 };
573 
574 /* HWS priority band setup request / response */
575 struct vpu_ipc_msg_payload_hws_priority_band_setup {
576 	/*
577 	 * Grace period in 100ns units when preempting another priority band for
578 	 * this priority band
579 	 */
580 	u64 grace_period[VPU_HWS_NUM_PRIORITY_BANDS];
581 	/*
582 	 * Default quantum in 100ns units for scheduling across processes
583 	 * within a priority band
584 	 */
585 	u64 process_quantum[VPU_HWS_NUM_PRIORITY_BANDS];
586 	/*
587 	 * Default grace period in 100ns units for processes that preempt each
588 	 * other within a priority band
589 	 */
590 	u64 process_grace_period[VPU_HWS_NUM_PRIORITY_BANDS];
591 	/*
592 	 * For normal priority band, specifies the target VPU percentage
593 	 * in situations when it's starved by the focus band.
594 	 */
595 	u32 normal_band_percentage;
596 };
597 
598 /* HWS create command queue request */
599 struct vpu_ipc_msg_payload_hws_create_cmdq {
600 	/* Process id */
601 	u64 process_id;
602 	/* Host SSID */
603 	u32 host_ssid;
604 	/* Zero Padding */
605 	u32 reserved;
606 	/* Command queue id */
607 	u64 cmdq_id;
608 	/* Command queue base */
609 	u64 cmdq_base;
610 	/* Command queue size */
611 	u32 cmdq_size;
612 };
613 
614 /* HWS create command queue response */
615 struct vpu_ipc_msg_payload_hws_create_cmdq_rsp {
616 	/* Process id */
617 	u64 process_id;
618 	/* Host SSID */
619 	u32 host_ssid;
620 	/* Zero Padding */
621 	u32 reserved;
622 	/* Command queue id */
623 	u64 cmdq_id;
624 };
625 
626 /* HWS destroy command queue request / response */
627 struct vpu_ipc_msg_payload_hws_destroy_cmdq {
628 	/* Host SSID */
629 	u32 host_ssid;
630 	/* Zero Padding */
631 	u32 reserved;
632 	/* Command queue id */
633 	u64 cmdq_id;
634 };
635 
636 /* HWS set context scheduling properties request / response */
637 struct vpu_ipc_msg_payload_hws_set_context_sched_properties {
638 	/* Host SSID */
639 	u32 host_ssid;
640 	/* Zero Padding */
641 	u32 reserved_0;
642 	/* Command queue id */
643 	u64 cmdq_id;
644 	/* Priority band to assign to work of this context */
645 	u32 priority_band;
646 	/* Inside realtime band assigns a further priority */
647 	u32 realtime_priority_level;
648 	/* Priority relative to other contexts in the same process */
649 	u32 in_process_priority;
650 	/* Zero padding / Reserved */
651 	u32 reserved_1;
652 	/* Context quantum relative to other contexts of same priority in the same process */
653 	u64 context_quantum;
654 	/* Grace period when preempting context of the same priority within the same process */
655 	u64 grace_period_same_priority;
656 	/* Grace period when preempting context of a lower priority within the same process */
657 	u64 grace_period_lower_priority;
658 };
659 
660 /*
661  * @brief Register doorbell command structure.
662  * This structure supports doorbell registration for both HW and OS scheduling.
663  * Note: Queue base and size are added here so that the same structure can be used for
664  * OS scheduling and HW scheduling. For OS scheduling, cmdq_id will be ignored
665  * and cmdq_base and cmdq_size will be used. For HW scheduling, cmdq_base and cmdq_size will be
666  * ignored and cmdq_id is used.
667  * @see VPU_JSM_MSG_HWS_REGISTER_DB
668  */
669 struct vpu_jsm_hws_register_db {
670 	/* Index of the doorbell to register. */
671 	u32 db_id;
672 	/* Host sub-stream ID for the context assigned to the doorbell. */
673 	u32 host_ssid;
674 	/* ID of the command queue associated with the doorbell. */
675 	u64 cmdq_id;
676 	/* Virtual address pointing to the start of command queue. */
677 	u64 cmdq_base;
678 	/* Size of the command queue in bytes. */
679 	u64 cmdq_size;
680 };
681 
682 /**
683  * Payload for VPU_JSM_MSG_TRACE_SET_CONFIG[_RSP] and
684  * VPU_JSM_MSG_TRACE_GET_CONFIG_RSP messages.
685  *
686  * The payload is interpreted differently depending on the type of message:
687  *
688  * - For VPU_JSM_MSG_TRACE_SET_CONFIG, the payload specifies the desired
689  *   logging configuration to be set.
690  *
691  * - For VPU_JSM_MSG_TRACE_SET_CONFIG_RSP, the payload reports the logging
692  *   configuration that was set after a VPU_JSM_MSG_TRACE_SET_CONFIG request.
693  *   The host can compare this payload with the one it sent in the
694  *   VPU_JSM_MSG_TRACE_SET_CONFIG request to check whether or not the
695  *   configuration was set as desired.
696  *
697  * - VPU_JSM_MSG_TRACE_GET_CONFIG_RSP, the payload reports the current logging
698  *   configuration.
699  */
700 struct vpu_ipc_msg_payload_trace_config {
701 	/**
702 	 * Logging level (currently set or to be set); see 'mvLog_t' enum for
703 	 * acceptable values. The specified logging level applies to all
704 	 * destinations and HW components
705 	 */
706 	u32 trace_level;
707 	/**
708 	 * Bitmask of logging destinations (currently enabled or to be enabled);
709 	 * bitwise OR of values defined in logging_destination enum.
710 	 */
711 	u32 trace_destination_mask;
712 	/**
713 	 * Bitmask of loggable HW components (currently enabled or to be enabled);
714 	 * bitwise OR of values defined in loggable_hw_component enum.
715 	 */
716 	u64 trace_hw_component_mask;
717 	u64 reserved_0; /**< Reserved for future extensions. */
718 };
719 
720 /**
721  * Payload for VPU_JSM_MSG_TRACE_GET_CAPABILITY_RSP messages.
722  */
723 struct vpu_ipc_msg_payload_trace_capability_rsp {
724 	u32 trace_destination_mask; /**< Bitmask of supported logging destinations. */
725 	u32 reserved_0;
726 	u64 trace_hw_component_mask; /**< Bitmask of supported loggable HW components. */
727 	u64 reserved_1; /**< Reserved for future extensions. */
728 };
729 
730 /**
731  * Payload for VPU_JSM_MSG_TRACE_GET_NAME requests.
732  */
733 struct vpu_ipc_msg_payload_trace_get_name {
734 	/**
735 	 * The type of the entity to query name for; see logging_entity_type for
736 	 * possible values.
737 	 */
738 	u32 entity_type;
739 	u32 reserved_0;
740 	/**
741 	 * The ID of the entity to query name for; possible values depends on the
742 	 * entity type.
743 	 */
744 	u64 entity_id;
745 };
746 
747 /**
748  * Payload for VPU_JSM_MSG_TRACE_GET_NAME_RSP responses.
749  */
750 struct vpu_ipc_msg_payload_trace_get_name_rsp {
751 	/**
752 	 * The type of the entity whose name was queried; see logging_entity_type
753 	 * for possible values.
754 	 */
755 	u32 entity_type;
756 	u32 reserved_0;
757 	/**
758 	 * The ID of the entity whose name was queried; possible values depends on
759 	 * the entity type.
760 	 */
761 	u64 entity_id;
762 	/** Reserved for future extensions. */
763 	u64 reserved_1;
764 	/** The name of the entity. */
765 	char entity_name[VPU_TRACE_ENTITY_NAME_MAX_LEN];
766 };
767 
768 /**
769  * Data sent from the VPU to the host in all metric streamer response messages
770  * and in asynchronous notification.
771  * @see VPU_JSM_MSG_METRIC_STREAMER_START_DONE
772  * @see VPU_JSM_MSG_METRIC_STREAMER_STOP_DONE
773  * @see VPU_JSM_MSG_METRIC_STREAMER_UPDATE_DONE
774  * @see VPU_JSM_MSG_METRIC_STREAMER_INFO_DONE
775  * @see VPU_JSM_MSG_METRIC_STREAMER_NOTIFICATION
776  */
777 struct vpu_jsm_metric_streamer_done {
778 	/** Metric group mask that identifies metric streamer instance. */
779 	u64 metric_group_mask;
780 	/**
781 	 * Size in bytes of single sample - total size of all enabled counters.
782 	 * Some VPU implementations may align sample_size to more than 8 bytes.
783 	 */
784 	u32 sample_size;
785 	u32 reserved_0;
786 	/**
787 	 * Number of samples collected since the metric streamer was started.
788 	 * This will be 0 if the metric streamer was not started.
789 	 */
790 	u32 samples_collected;
791 	/**
792 	 * Number of samples dropped since the metric streamer was started. This
793 	 * is incremented every time the metric streamer is not able to write
794 	 * collected samples because the current buffer is full and there is no
795 	 * next buffer to switch to.
796 	 */
797 	u32 samples_dropped;
798 	/** Address of the buffer that contains the latest metric data. */
799 	u64 buffer_addr;
800 	/**
801 	 * Number of bytes written into the metric data buffer. In response to the
802 	 * VPU_JSM_MSG_METRIC_STREAMER_INFO request this field contains the size of
803 	 * all group and counter descriptors. The size is updated even if the buffer
804 	 * in the request was NULL or too small to hold descriptors of all counters
805 	 */
806 	u64 bytes_written;
807 };
808 
809 static_assert(sizeof(struct vpu_jsm_metric_streamer_done) % 8 == 0,
810 	      "vpu_jsm_metric_streamer_done is misaligned");
811 
812 /**
813  * Metric group description placed in the metric buffer after successful completion
814  * of the VPU_JSM_MSG_METRIC_STREAMER_INFO command. This is followed by one or more
815  * @vpu_jsm_metric_counter_descriptor records.
816  * @see VPU_JSM_MSG_METRIC_STREAMER_INFO
817  */
818 struct vpu_jsm_metric_group_descriptor {
819 	/**
820 	 * Offset to the next metric group (8-byte aligned). If this offset is 0 this
821 	 * is the last descriptor. The value of metric_info_size must be greater than
822 	 * or equal to sizeof(struct vpu_jsm_metric_group_descriptor) + name_string_size
823 	 * + description_string_size and must be 8-byte aligned.
824 	 */
825 	u32 next_metric_group_info_offset;
826 	/**
827 	 * Offset to the first metric counter description record (8-byte aligned).
828 	 * @see vpu_jsm_metric_counter_descriptor
829 	 */
830 	u32 next_metric_counter_info_offset;
831 	/** Index of the group. This corresponds to bit index in metric_group_mask. */
832 	u32 group_id;
833 	/** Number of counters in the metric group. */
834 	u32 num_counters;
835 	/** Data size for all counters, must be a multiple of 8 bytes.*/
836 	u32 metric_group_data_size;
837 	/**
838 	 * Metric group domain number. Cannot use multiple, simultaneous metric groups
839 	 * from the same domain.
840 	 */
841 	u32 domain;
842 	/**
843 	 * Counter name string size. The string must include a null termination character.
844 	 * The FW may use a fixed size name or send a different name for each counter.
845 	 * If the VPU uses fixed size strings, all characters from the end of the name
846 	 * to the of the fixed size character array must be zeroed.
847 	 */
848 	u32 name_string_size;
849 	/** Counter description string size, @see name_string_size */
850 	u32 description_string_size;
851 	u32 reserved_0[2];
852 	/**
853 	 * Right after this structure, the VPU writes name and description of
854 	 * the metric group.
855 	 */
856 };
857 
858 static_assert(sizeof(struct vpu_jsm_metric_group_descriptor) % 8 == 0,
859 	      "vpu_jsm_metric_group_descriptor is misaligned");
860 
861 /**
862  * Metric counter description, placed in the buffer after vpu_jsm_metric_group_descriptor.
863  * @see VPU_JSM_MSG_METRIC_STREAMER_INFO
864  */
865 struct vpu_jsm_metric_counter_descriptor {
866 	/**
867 	 * Offset to the next counter in a group (8-byte aligned). If this offset is
868 	 * 0 this is the last counter in the group.
869 	 */
870 	u32 next_metric_counter_info_offset;
871 	/**
872 	 * Offset to the counter data from the start of samples in this metric group.
873 	 * Note that metric_data_offset % metric_data_size must be 0.
874 	 */
875 	u32 metric_data_offset;
876 	/** Size of the metric counter data in bytes. */
877 	u32 metric_data_size;
878 	/** Metric type, see Level Zero API for definitions. */
879 	u32 tier;
880 	/** Metric type, see set_metric_type_t for definitions. */
881 	u32 metric_type;
882 	/** Metric type, see set_value_type_t for definitions. */
883 	u32 metric_value_type;
884 	/**
885 	 * Counter name string size. The string must include a null termination character.
886 	 * The FW may use a fixed size name or send a different name for each counter.
887 	 * If the VPU uses fixed size strings, all characters from the end of the name
888 	 * to the of the fixed size character array must be zeroed.
889 	 */
890 	u32 name_string_size;
891 	/** Counter description string size, @see name_string_size */
892 	u32 description_string_size;
893 	/** Counter component name string size, @see name_string_size */
894 	u32 component_string_size;
895 	/** Counter string size, @see name_string_size */
896 	u32 units_string_size;
897 	u32 reserved_0[2];
898 	/**
899 	 * Right after this structure, the VPU writes name, description
900 	 * component and unit strings.
901 	 */
902 };
903 
904 static_assert(sizeof(struct vpu_jsm_metric_counter_descriptor) % 8 == 0,
905 	      "vpu_jsm_metric_counter_descriptor is misaligned");
906 
907 /**
908  * Payload for VPU_JSM_MSG_DYNDBG_CONTROL requests.
909  *
910  * VPU_JSM_MSG_DYNDBG_CONTROL are used to control the VPU FW Dynamic Debug
911  * feature, which allows developers to selectively enable / disable MVLOG_DEBUG
912  * messages. This is equivalent to the Dynamic Debug functionality provided by
913  * Linux
914  * (https://www.kernel.org/doc/html/latest/admin-guide/dynamic-debug-howto.html)
915  * The host can control Dynamic Debug behavior by sending dyndbg commands, which
916  * have the same syntax as Linux
917  * dyndbg commands.
918  *
919  * NOTE: in order for MVLOG_DEBUG messages to be actually printed, the host
920  * still has to set the logging level to MVLOG_DEBUG, using the
921  * VPU_JSM_MSG_TRACE_SET_CONFIG command.
922  *
923  * The host can see the current dynamic debug configuration by executing a
924  * special 'show' command. The dyndbg configuration will be printed to the
925  * configured logging destination using MVLOG_INFO logging level.
926  */
927 struct vpu_ipc_msg_payload_dyndbg_control {
928 	/**
929 	 * Dyndbg command (same format as Linux dyndbg); must be a NULL-terminated
930 	 * string.
931 	 */
932 	char dyndbg_cmd[VPU_DYNDBG_CMD_MAX_LEN];
933 };
934 
935 /*
936  * Payloads union, used to define complete message format.
937  */
938 union vpu_ipc_msg_payload {
939 	struct vpu_ipc_msg_payload_engine_reset engine_reset;
940 	struct vpu_ipc_msg_payload_engine_preempt engine_preempt;
941 	struct vpu_ipc_msg_payload_register_db register_db;
942 	struct vpu_ipc_msg_payload_unregister_db unregister_db;
943 	struct vpu_ipc_msg_payload_query_engine_hb query_engine_hb;
944 	struct vpu_ipc_msg_payload_power_level power_level;
945 	struct vpu_jsm_metric_streamer_start metric_streamer_start;
946 	struct vpu_jsm_metric_streamer_stop metric_streamer_stop;
947 	struct vpu_jsm_metric_streamer_update metric_streamer_update;
948 	struct vpu_ipc_msg_payload_blob_deinit blob_deinit;
949 	struct vpu_ipc_msg_payload_ssid_release ssid_release;
950 	struct vpu_jsm_hws_register_db hws_register_db;
951 	struct vpu_ipc_msg_payload_job_done job_done;
952 	struct vpu_ipc_msg_payload_engine_reset_done engine_reset_done;
953 	struct vpu_ipc_msg_payload_engine_preempt_done engine_preempt_done;
954 	struct vpu_ipc_msg_payload_register_db_done register_db_done;
955 	struct vpu_ipc_msg_payload_unregister_db_done unregister_db_done;
956 	struct vpu_ipc_msg_payload_query_engine_hb_done query_engine_hb_done;
957 	struct vpu_ipc_msg_payload_get_power_level_count_done get_power_level_count_done;
958 	struct vpu_jsm_metric_streamer_done metric_streamer_done;
959 	struct vpu_ipc_msg_payload_blob_deinit_done blob_deinit_done;
960 	struct vpu_ipc_msg_payload_trace_config trace_config;
961 	struct vpu_ipc_msg_payload_trace_capability_rsp trace_capability;
962 	struct vpu_ipc_msg_payload_trace_get_name trace_get_name;
963 	struct vpu_ipc_msg_payload_trace_get_name_rsp trace_get_name_rsp;
964 	struct vpu_ipc_msg_payload_dyndbg_control dyndbg_control;
965 	struct vpu_ipc_msg_payload_hws_priority_band_setup hws_priority_band_setup;
966 	struct vpu_ipc_msg_payload_hws_create_cmdq hws_create_cmdq;
967 	struct vpu_ipc_msg_payload_hws_create_cmdq_rsp hws_create_cmdq_rsp;
968 	struct vpu_ipc_msg_payload_hws_destroy_cmdq hws_destroy_cmdq;
969 	struct vpu_ipc_msg_payload_hws_set_context_sched_properties
970 		hws_set_context_sched_properties;
971 };
972 
973 /*
974  * Host <-> LRT IPC message base structure.
975  *
976  * NOTE: All instances of this object must be aligned on a 64B boundary
977  * to allow proper handling of VPU cache operations.
978  */
979 struct vpu_jsm_msg {
980 	/* Message type, see vpu_ipc_msg_type enum. */
981 	u32 type;
982 	/* Buffer status, see vpu_ipc_msg_status enum. */
983 	u32 status;
984 	/*
985 	 * Request ID, provided by the host in a request message and passed
986 	 * back by VPU in the response message.
987 	 */
988 	u32 request_id;
989 	/* Request return code set by the VPU, see VPU_JSM_STATUS_* defines. */
990 	u32 result;
991 	/* Message payload depending on message type, see vpu_ipc_msg_payload union. */
992 	union vpu_ipc_msg_payload payload;
993 };
994 
995 #pragma pack(pop)
996 
997 #endif
998 
999 ///@}
1000