1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * Copyright (C) 2024, Advanced Micro Devices, Inc.
4 */
5
6 #include <drm/amdxdna_accel.h>
7 #include <drm/drm_device.h>
8 #include <drm/drm_print.h>
9 #include <drm/drm_gem.h>
10 #include <drm/drm_gem_shmem_helper.h>
11 #include <drm/gpu_scheduler.h>
12 #include <linux/completion.h>
13
14 #include "amdxdna_gem.h"
15 #include "amdxdna_mailbox.h"
16 #include "amdxdna_mailbox_helper.h"
17 #include "amdxdna_pci_drv.h"
18
xdna_msg_cb(void * handle,const u32 * data,size_t size)19 int xdna_msg_cb(void *handle, const u32 *data, size_t size)
20 {
21 struct xdna_notify *cb_arg = handle;
22 int ret;
23
24 if (unlikely(!data))
25 goto out;
26
27 if (unlikely(cb_arg->size != size)) {
28 cb_arg->error = -EINVAL;
29 goto out;
30 }
31
32 print_hex_dump_debug("resp data: ", DUMP_PREFIX_OFFSET,
33 16, 4, data, cb_arg->size, true);
34 memcpy(cb_arg->data, data, cb_arg->size);
35 out:
36 ret = cb_arg->error;
37 complete(&cb_arg->comp);
38 return ret;
39 }
40
xdna_send_msg_wait(struct amdxdna_dev * xdna,struct mailbox_channel * chann,struct xdna_mailbox_msg * msg)41 int xdna_send_msg_wait(struct amdxdna_dev *xdna, struct mailbox_channel *chann,
42 struct xdna_mailbox_msg *msg)
43 {
44 struct xdna_notify *hdl = msg->handle;
45 int ret;
46
47 ret = xdna_mailbox_send_msg(chann, msg, TX_TIMEOUT);
48 if (ret) {
49 XDNA_ERR(xdna, "Send message failed, ret %d", ret);
50 return ret;
51 }
52
53 ret = wait_for_completion_timeout(&hdl->comp,
54 msecs_to_jiffies(RX_TIMEOUT));
55 if (!ret) {
56 XDNA_ERR(xdna, "Wait for completion timeout");
57 return -ETIME;
58 }
59
60 return hdl->error;
61 }
62