xref: /freebsd/sys/compat/linuxkpi/common/include/linux/mhi.h (revision 5ca8e32633c4ffbbcd6762e5888b6a4ba0708c6c)
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause
3  *
4  * Copyright (c) 2022-2023 Bjoern A. Zeeb
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25  * SUCH DAMAGE.
26  */
27 
28 #ifndef	_LINUXKPI_LINUX_MHI_H
29 #define	_LINUXKPI_LINUX_MHI_H
30 
31 #include <linux/types.h>
32 
33 /* Modem Host Interface (MHI) */
34 
35 /* XXX FIXME */
36 #define	MHI_DB_BRST_DISABLE	0
37 #define	MHI_ER_CTRL		0
38 
39 enum mhi_callback {
40 	MHI_CB_SYS_ERROR,
41 	MHI_CB_BW_REQ,
42 	MHI_CB_EE_MISSION_MODE,
43 	MHI_CB_EE_RDDM,
44 	MHI_CB_FATAL_ERROR,
45 	MHI_CB_IDLE,
46 	MHI_CB_LPM_ENTER,
47 	MHI_CB_LPM_EXIT,
48 	MHI_CB_PENDING_DATA,
49 };
50 
51 struct mhi_channel_config {
52 	const char		*name;
53 	int	auto_queue, dir, doorbell, doorbell_mode_switch, ee_mask, event_ring, lpm_notify, num, num_elements, offload_channel, pollcfg;
54 };
55 
56 struct mhi_event_config {
57 	int	client_managed, data_type, hardware_event, irq, irq_moderation_ms, mode, num_elements, offload_channel, priority;
58 };
59 
60 struct mhi_device {
61 };
62 
63 struct mhi_controller_config {
64 	const struct mhi_channel_config	*ch_cfg;
65 	struct mhi_event_config		*event_cfg;
66 
67 	int	buf_len, max_channels, num_channels, num_events, use_bounce_buf;
68 
69 	uint32_t			timeout_ms;
70 };
71 
72 struct mhi_controller {
73 	struct device			*cntrl_dev;
74 	struct mhi_device		*mhi_dev;
75 	void				*regs;
76 	int				*irq;
77 	const char			*fw_image;
78 
79 	bool				fbc_download;
80 	size_t				rddm_size;
81 	size_t				sbl_size;
82 	size_t				seg_len;
83 	size_t				reg_len;
84 	int				nr_irqs;
85 	unsigned long			irq_flags;
86 	uint32_t			timeout_ms;
87 
88 	dma_addr_t			iova_start;
89 	dma_addr_t			iova_stop;
90 
91 	int				(*runtime_get)(struct mhi_controller *);
92 	void				(*runtime_put)(struct mhi_controller *);
93 	void				(*status_cb)(struct mhi_controller *, enum mhi_callback);
94 	int				(*read_reg)(struct mhi_controller *, void __iomem *, uint32_t *);
95 	void				(*write_reg)(struct mhi_controller *, void __iomem *, uint32_t);
96 };
97 
98 /* -------------------------------------------------------------------------- */
99 
100 struct mhi_controller *linuxkpi_mhi_alloc_controller(void);
101 void linuxkpi_mhi_free_controller(struct mhi_controller *);
102 int linuxkpi_mhi_register_controller(struct mhi_controller *,
103     const struct mhi_controller_config *);
104 void linuxkpi_mhi_unregister_controller(struct mhi_controller *);
105 
106 /* -------------------------------------------------------------------------- */
107 
108 static inline struct mhi_controller *
109 mhi_alloc_controller(void)
110 {
111 
112 	/* Keep allocations internal to our implementation. */
113 	return (linuxkpi_mhi_alloc_controller());
114 }
115 
116 static inline void
117 mhi_free_controller(struct mhi_controller *mhi_ctrl)
118 {
119 
120 	linuxkpi_mhi_free_controller(mhi_ctrl);
121 }
122 
123 static inline int
124 mhi_register_controller(struct mhi_controller *mhi_ctrl,
125     const struct mhi_controller_config *cfg)
126 {
127 
128 	return (linuxkpi_mhi_register_controller(mhi_ctrl, cfg));
129 }
130 
131 static inline void
132 mhi_unregister_controller(struct mhi_controller *mhi_ctrl)
133 {
134 
135 	linuxkpi_mhi_unregister_controller(mhi_ctrl);
136 }
137 
138 /* -------------------------------------------------------------------------- */
139 
140 static __inline int
141 mhi_device_get_sync(struct mhi_device *mhi_dev)
142 {
143 	/* XXX TODO */
144 	return (-1);
145 }
146 
147 static __inline void
148 mhi_device_put(struct mhi_device *mhi_dev)
149 {
150 	/* XXX TODO */
151 }
152 
153 /* -------------------------------------------------------------------------- */
154 
155 static __inline int
156 mhi_prepare_for_power_up(struct mhi_controller *mhi_ctrl)
157 {
158 	/* XXX TODO */
159 	return (0);
160 }
161 
162 static __inline int
163 mhi_sync_power_up(struct mhi_controller *mhi_ctrl)
164 {
165 	/* XXX TODO */
166 	return (0);
167 }
168 
169 static __inline int
170 mhi_async_power_up(struct mhi_controller *mhi_ctrl)
171 {
172 	/* XXX TODO */
173 	return (0);
174 }
175 
176 static __inline void
177 mhi_power_down(struct mhi_controller *mhi_ctrl, bool x)
178 {
179 	/* XXX TODO */
180 }
181 
182 static __inline void
183 mhi_unprepare_after_power_down(struct mhi_controller *mhi_ctrl)
184 {
185 	/* XXX TODO */
186 }
187 
188 /* -------------------------------------------------------------------------- */
189 
190 static __inline int
191 mhi_pm_suspend(struct mhi_controller *mhi_ctrl)
192 {
193 	/* XXX TODO */
194 	return (0);
195 }
196 
197 static __inline int
198 mhi_pm_resume(struct mhi_controller *mhi_ctrl)
199 {
200 	/* XXX TODO */
201 	return (0);
202 }
203 
204 static __inline int
205 mhi_pm_resume_force(struct mhi_controller *mhi_ctrl)
206 {
207 	/* XXX TODO */
208 	return (0);
209 }
210 
211 /* -------------------------------------------------------------------------- */
212 
213 static __inline int
214 mhi_force_rddm_mode(struct mhi_controller *mhi_ctrl)
215 {
216 	/* XXX TODO */
217 	return (0);
218 }
219 
220 #endif	/* _LINUXKPI_LINUX_MHI_H */
221