1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * Copyright (C) 2020-2024 Intel Corporation
9 #include <linux/interrupt.h>
10 #include <linux/spinlock.h>
12 #include "vpu_jsm_api.h"
16 /* VPU FW boot notification */
17 #define IVPU_IPC_CHAN_BOOT_MSG 0x3ff
18 #define IVPU_IPC_BOOT_MSG_DATA_ADDR 0x424f4f54
20 /* The alignment to be used for IPC Buffers and IPC Data. */
21 #define IVPU_IPC_ALIGNMENT 64
23 #define IVPU_IPC_HDR_FREE 0
24 #define IVPU_IPC_HDR_ALLOCATED 1
27 * struct ivpu_ipc_hdr - The IPC message header structure, exchanged
28 * with the VPU device firmware.
29 * @data_addr: The VPU address of the payload (JSM message)
30 * @data_size: The size of the payload.
31 * @channel: The channel used.
32 * @src_node: The Node ID of the sender.
33 * @dst_node: The Node ID of the intended receiver.
34 * @status: IPC buffer usage status
43 } __packed
__aligned(IVPU_IPC_ALIGNMENT
);
45 typedef void (*ivpu_ipc_rx_callback_t
)(struct ivpu_device
*vdev
,
46 struct ivpu_ipc_hdr
*ipc_hdr
,
47 struct vpu_jsm_msg
*jsm_msg
);
49 struct ivpu_ipc_rx_msg
{
50 struct list_head link
;
51 struct ivpu_ipc_hdr
*ipc_hdr
;
52 struct vpu_jsm_msg
*jsm_msg
;
53 ivpu_ipc_rx_callback_t callback
;
56 struct ivpu_ipc_consumer
{
57 struct list_head link
;
62 ivpu_ipc_rx_callback_t rx_callback
;
64 spinlock_t rx_lock
; /* Protects rx_msg_list and aborted */
65 struct list_head rx_msg_list
;
66 wait_queue_head_t rx_msg_wq
;
69 struct ivpu_ipc_info
{
70 struct gen_pool
*mm_tx
;
71 struct ivpu_bo
*mem_tx
;
72 struct ivpu_bo
*mem_rx
;
74 atomic_t rx_msg_count
;
76 spinlock_t cons_lock
; /* Protects cons_list and cb_msg_list */
77 struct list_head cons_list
;
78 struct list_head cb_msg_list
;
81 struct mutex lock
; /* Lock on status */
85 int ivpu_ipc_init(struct ivpu_device
*vdev
);
86 void ivpu_ipc_fini(struct ivpu_device
*vdev
);
88 void ivpu_ipc_enable(struct ivpu_device
*vdev
);
89 void ivpu_ipc_disable(struct ivpu_device
*vdev
);
90 void ivpu_ipc_reset(struct ivpu_device
*vdev
);
92 void ivpu_ipc_irq_handler(struct ivpu_device
*vdev
);
93 void ivpu_ipc_irq_work_fn(struct work_struct
*work
);
95 void ivpu_ipc_consumer_add(struct ivpu_device
*vdev
, struct ivpu_ipc_consumer
*cons
,
96 u32 channel
, ivpu_ipc_rx_callback_t callback
);
97 void ivpu_ipc_consumer_del(struct ivpu_device
*vdev
, struct ivpu_ipc_consumer
*cons
);
99 int ivpu_ipc_send(struct ivpu_device
*vdev
, struct ivpu_ipc_consumer
*cons
,
100 struct vpu_jsm_msg
*req
);
101 int ivpu_ipc_receive(struct ivpu_device
*vdev
, struct ivpu_ipc_consumer
*cons
,
102 struct ivpu_ipc_hdr
*ipc_buf
, struct vpu_jsm_msg
*jsm_msg
,
103 unsigned long timeout_ms
);
104 int ivpu_ipc_send_receive_internal(struct ivpu_device
*vdev
, struct vpu_jsm_msg
*req
,
105 enum vpu_ipc_msg_type expected_resp_type
,
106 struct vpu_jsm_msg
*resp
, u32 channel
, unsigned long timeout_ms
);
107 int ivpu_ipc_send_receive(struct ivpu_device
*vdev
, struct vpu_jsm_msg
*req
,
108 enum vpu_ipc_msg_type expected_resp
, struct vpu_jsm_msg
*resp
,
109 u32 channel
, unsigned long timeout_ms
);
110 int ivpu_ipc_send_and_wait(struct ivpu_device
*vdev
, struct vpu_jsm_msg
*req
,
111 u32 channel
, unsigned long timeout_ms
);
113 #endif /* __IVPU_IPC_H__ */