xref: /linux/drivers/accel/amdxdna/amdxdna_mailbox.h (revision dfb31428444b00824b161d8c0741d4868552813a)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * Copyright (C) 2022-2024, Advanced Micro Devices, Inc.
4  */
5 
6 #ifndef _AIE2_MAILBOX_H_
7 #define _AIE2_MAILBOX_H_
8 
9 struct mailbox;
10 struct mailbox_channel;
11 
12 /*
13  * xdna_mailbox_msg - message struct
14  *
15  * @opcode:	opcode for firmware
16  * @handle:	handle used for the notify callback
17  * @notify_cb:  callback function to notify the sender when there is response
18  * @send_data:	pointing to sending data
19  * @send_size:	size of the sending data
20  *
21  * The mailbox will split the sending data in to multiple firmware message if
22  * the size of the data is too big. This is transparent to the sender. The
23  * sender will receive one notification.
24  */
25 struct xdna_mailbox_msg {
26 	u32		opcode;
27 	void		*handle;
28 	int		(*notify_cb)(void *handle, void __iomem *data, size_t size);
29 	u8		*send_data;
30 	size_t		send_size;
31 };
32 
33 /*
34  * xdna_mailbox_res - mailbox hardware resource
35  *
36  * @ringbuf_base:	ring buffer base address
37  * @ringbuf_size:	ring buffer size
38  * @mbox_base:		mailbox base address
39  * @mbox_size:		mailbox size
40  */
41 struct xdna_mailbox_res {
42 	void __iomem	*ringbuf_base;
43 	size_t		ringbuf_size;
44 	void __iomem	*mbox_base;
45 	size_t		mbox_size;
46 	const char	*name;
47 };
48 
49 /*
50  * xdna_mailbox_chann_res - resources
51  *
52  * @rb_start_addr:	ring buffer start address
53  * @rb_size:		ring buffer size
54  * @mb_head_ptr_reg:	mailbox head pointer register
55  * @mb_tail_ptr_reg:	mailbox tail pointer register
56  */
57 struct xdna_mailbox_chann_res {
58 	u32 rb_start_addr;
59 	u32 rb_size;
60 	u32 mb_head_ptr_reg;
61 	u32 mb_tail_ptr_reg;
62 };
63 
64 /*
65  * xdna_mailbox_create() -- create mailbox subsystem and initialize
66  *
67  * @ddev: device pointer
68  * @res: SRAM and mailbox resources
69  *
70  * Return: If success, return a handle of mailbox subsystem.
71  * Otherwise, return NULL pointer.
72  */
73 struct mailbox *xdnam_mailbox_create(struct drm_device *ddev,
74 				     const struct xdna_mailbox_res *res);
75 
76 /*
77  * xdna_mailbox_alloc_channel() -- alloc a mailbox channel
78  *
79  * @mb: mailbox handle
80  */
81 struct mailbox_channel *xdna_mailbox_alloc_channel(struct mailbox *mb);
82 
83 /*
84  * xdna_mailbox_start_channel() -- start a mailbox channel instance
85  *
86  * @mb_chann: the handle return from xdna_mailbox_alloc_channel()
87  * @x2i: host to firmware mailbox resources
88  * @i2x: firmware to host mailbox resources
89  * @xdna_mailbox_intr_reg: register addr of MSI-X interrupt
90  * @mb_irq: Linux IRQ number associated with mailbox MSI-X interrupt vector index
91  *
92  * Return: If success, return a handle of mailbox channel. Otherwise, return NULL.
93  */
94 int
95 xdna_mailbox_start_channel(struct mailbox_channel *mb_chann,
96 			   const struct xdna_mailbox_chann_res *x2i,
97 			   const struct xdna_mailbox_chann_res *i2x,
98 			   u32 xdna_mailbox_intr_reg,
99 			   int mb_irq);
100 
101 /*
102  * xdna_mailbox_free_channel() -- free mailbox channel
103  *
104  * @mailbox_chann: the handle return from xdna_mailbox_create_channel()
105  */
106 void xdna_mailbox_free_channel(struct mailbox_channel *mailbox_chann);
107 
108 /*
109  * xdna_mailbox_stop_channel() -- stop mailbox channel
110  *
111  * @mailbox_chann: the handle return from xdna_mailbox_create_channel()
112  */
113 void xdna_mailbox_stop_channel(struct mailbox_channel *mailbox_chann);
114 
115 /*
116  * xdna_mailbox_send_msg() -- Send a message
117  *
118  * @mailbox_chann: Mailbox channel handle
119  * @msg: message struct for message information
120  * @tx_timeout: the timeout value for sending the message in ms.
121  *
122  * Return: If success return 0, otherwise, return error code
123  */
124 int xdna_mailbox_send_msg(struct mailbox_channel *mailbox_chann,
125 			  const struct xdna_mailbox_msg *msg, u64 tx_timeout);
126 
127 #endif /* _AIE2_MAILBOX_ */
128