Debian Codegraph @

src/deps/miniasync/extras/dml/utils/util_dml.c

raw
1 // SPDX-License-Identifier: BSD-3-Clause
2 /* Copyright 2022, Intel Corporation */
3
4 #include <assert.h>
5 #include <stdio.h>
6 #include <stdlib.h>
7
8 #include <dml/dml.h>
9
10 #include "cpu.h"
11
12 /*
13 * util_dml_check_hw_available -- check DML operations with hardware path can
14 * be performed on current platform. Returns '0'
15 * when it's available and '-1' when it's not.
16 */
17 int
18 util_dml_check_hw_available()
19 {
20 if (!is_cpu_movdir64b_present()) {
21 return -1;
22 }
23
24 int ret = 0;
25 size_t buf_alloc_size = sizeof(char);
26 char *buf = malloc(buf_alloc_size);
27 char *dst = malloc(buf_alloc_size);
28
29 dml_status_t status;
30 uint32_t job_size;
31 dml_job_t *dml_job_ptr;
32
33 status = dml_get_job_size(DML_PATH_HW, &job_size);
34 if (status != DML_STATUS_OK) {
35 ret = -1;
36 goto free_bufs;
37 }
38
39 dml_job_ptr = (dml_job_t *)malloc(job_size);
40
41 status = dml_init_job(DML_PATH_HW, dml_job_ptr);
42 if (status != DML_STATUS_OK) {
43 ret = -1;
44 goto free_job_ptr;
45 }
46
47 dml_job_ptr->operation = DML_OP_MEM_MOVE;
48 dml_job_ptr->source_first_ptr = (uint8_t *)buf;
49 dml_job_ptr->destination_first_ptr = (uint8_t *)dst;
50 dml_job_ptr->source_length = buf_alloc_size;
51 dml_job_ptr->destination_length = buf_alloc_size;
52
53 status = dml_execute_job(dml_job_ptr);
54 if (status != DML_STATUS_OK) {
55 ret = -1;
56 }
57
58 status = dml_finalize_job(dml_job_ptr);
59 assert(status == DML_STATUS_OK);
60 free_job_ptr:
61 free(dml_job_ptr);
62 free_bufs:
63 free(dst);
64 free(buf);
65
66 return ret;
67 }