1 /*
2  * SPDX-License-Identifier: BSD-3-Clause
3  *
4  * Copyright(c) 2019 Intel Corporation. All rights reserved.
5  *
6  * Author: Liam Girdwood <liam.r.girdwood@linux.intel.com>
7  */
8 
9 #ifndef IO_BRIDGE_H
10 #define IO_BRIDGE_H
11 
12 #include <stdint.h>
13 
14 #define QEMU_IO_DEBUG           0
15 
16 /* IO type */
17 #define QEMU_IO_TYPE_QEMU       0
18 #define QEMU_IO_TYPE_REG        1
19 #define QEMU_IO_TYPE_IRQ        2
20 #define QEMU_IO_TYPE_GDB        3
21 #define QEMU_IO_TYPE_PM         4
22 #define QEMU_IO_TYPE_DMA        5
23 #define QEMU_IO_TYPE_MEM        6
24 
25 /* Global Message Reply */
26 #define QEMU_IO_MSG_REPLY       0
27 
28 /* Register Messages */
29 #define QEMU_IO_MSG_REG32W      32
30 #define QEMU_IO_MSG_REG64W      33
31 #define QEMU_IO_MSG_REG32R      34
32 #define QEMU_IO_MSG_REG64R      35
33 
34 /* IRQ Messages */
35 #define QEMU_IO_MSG_IRQ         64
36 
37 /* DMA Messages */
38 #define QEMU_IO_DMA_REQ_NEW     96
39 #define QEMU_IO_DMA_REQ_READY   97
40 #define QEMU_IO_DMA_REQ_COMPLETE    98
41 
42 /* DMA Direction - relative to msg sender */
43 #define QEMU_IO_DMA_DIR_READ    256
44 #define QEMU_IO_DMA_DIR_WRITE   257
45 
46 /* GDB Messages */
47 #define QEMU_IO_GDB_STALL       128
48 #define QEMU_IO_GDB_CONT        129
49 #define QEMU_IO_GDB_STALL_RPLY  130 /* stall after reply */
50 
51 /* PM Messages */
52 #define QEMU_IO_PM_S0           192
53 #define QEMU_IO_PM_S1           193
54 #define QEMU_IO_PM_S2           194
55 #define QEMU_IO_PM_S3           195
56 #define QEMU_IO_PM_D0           196
57 #define QEMU_IO_PM_D1           197
58 #define QEMU_IO_PM_D2           198
59 #define QEMU_IO_PM_D3           199
60 
61 /* Common message header */
62 struct qemu_io_msg {
63 	uint16_t type;
64 	uint16_t msg;
65 	uint32_t size;
66 	uint32_t id;
67 };
68 
69 /* Generic message reply */
70 struct qemu_io_msg_reply {
71 	struct qemu_io_msg hdr;
72 	uint32_t reply;
73 };
74 
75 /* Register messages */
76 struct qemu_io_msg_reg32 {
77 	struct qemu_io_msg hdr;
78 	uint32_t reg;
79 	uint32_t val;
80 };
81 
82 struct qemu_io_msg_reg64 {
83 	struct qemu_io_msg hdr;
84 	uint64_t reg;
85 	uint64_t val;
86 };
87 
88 /* IRQ Messages */
89 struct qemu_io_msg_irq {
90 	struct qemu_io_msg hdr;
91 	uint32_t irq;
92 };
93 
94 /* PM Messages */
95 struct qemu_io_msg_pm_state {
96 	struct qemu_io_msg hdr;
97 };
98 
99 /* DMA Messages - same message used as reply */
100 struct qemu_io_msg_dma32 {
101 	struct qemu_io_msg hdr;
102 	uint32_t direction;	/*  QEMU_IO_DMA_DIR_ */
103 	uint32_t reply;		/* 0 or errno */
104 	uint32_t src;
105 	uint32_t dest;
106 	uint32_t size;
107 	uint32_t dmac_id;
108 	uint32_t chan_id;
109 	uint64_t host_data;
110 	uint64_t client_data;
111 };
112 
113 struct qemu_io_msg_dma64 {
114 	struct qemu_io_msg hdr;
115 	uint32_t direction;	/*  QEMU_IO_DMA_DIR_ */
116 	uint32_t reply;		/* 0 or errno */
117 	uint64_t src;
118 	uint64_t dest;
119 	uint64_t size;
120 	uint32_t dmac_id;
121 	uint32_t chan_id;
122 	uint64_t host_data;
123 	uint64_t client_data;
124 };
125 
126 /* API calls for parent and child */
127 int qemu_io_register_parent(const char *name,
128 			    int (*cb)(void *, struct qemu_io_msg *msg),
129 			    void *data);
130 int qemu_io_register_child(const char *name,
131 			   int (*cb)(void *, struct qemu_io_msg *msg),
132 			   void *data);
133 
134 int qemu_io_send_msg(struct qemu_io_msg *msg);
135 int qemu_io_send_msg_reply(struct qemu_io_msg *msg);
136 
137 int qemu_io_register_shm(const char *name, int region, size_t size,
138 			 void **addr);
139 int qemu_io_sync(int region, unsigned int offset, size_t length);
140 
141 void qemu_io_free(void);
142 void qemu_io_free_shm(int region);
143 
144 #endif
145