xref: /freebsd/sys/compat/linuxkpi/common/include/linux/mhi.h (revision c12e3a05252ac9f43a6db379f88e4b4a07c06d46)
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 	const u8			*fw_data;
79 	size_t				fw_sz;
80 
81 	bool				fbc_download;
82 	size_t				rddm_size;
83 	size_t				sbl_size;
84 	size_t				seg_len;
85 	size_t				reg_len;
86 	int				nr_irqs;
87 	unsigned long			irq_flags;
88 	uint32_t			timeout_ms;
89 
90 	dma_addr_t			iova_start;
91 	dma_addr_t			iova_stop;
92 
93 	int				(*runtime_get)(struct mhi_controller *);
94 	void				(*runtime_put)(struct mhi_controller *);
95 	void				(*status_cb)(struct mhi_controller *, enum mhi_callback);
96 	int				(*read_reg)(struct mhi_controller *, void __iomem *, uint32_t *);
97 	void				(*write_reg)(struct mhi_controller *, void __iomem *, uint32_t);
98 };
99 
100 /* -------------------------------------------------------------------------- */
101 
102 struct mhi_controller *linuxkpi_mhi_alloc_controller(void);
103 void linuxkpi_mhi_free_controller(struct mhi_controller *);
104 int linuxkpi_mhi_register_controller(struct mhi_controller *,
105     const struct mhi_controller_config *);
106 void linuxkpi_mhi_unregister_controller(struct mhi_controller *);
107 
108 /* -------------------------------------------------------------------------- */
109 
110 static inline struct mhi_controller *
mhi_alloc_controller(void)111 mhi_alloc_controller(void)
112 {
113 
114 	/* Keep allocations internal to our implementation. */
115 	return (linuxkpi_mhi_alloc_controller());
116 }
117 
118 static inline void
mhi_free_controller(struct mhi_controller * mhi_ctrl)119 mhi_free_controller(struct mhi_controller *mhi_ctrl)
120 {
121 
122 	linuxkpi_mhi_free_controller(mhi_ctrl);
123 }
124 
125 static inline int
mhi_register_controller(struct mhi_controller * mhi_ctrl,const struct mhi_controller_config * cfg)126 mhi_register_controller(struct mhi_controller *mhi_ctrl,
127     const struct mhi_controller_config *cfg)
128 {
129 
130 	return (linuxkpi_mhi_register_controller(mhi_ctrl, cfg));
131 }
132 
133 static inline void
mhi_unregister_controller(struct mhi_controller * mhi_ctrl)134 mhi_unregister_controller(struct mhi_controller *mhi_ctrl)
135 {
136 
137 	linuxkpi_mhi_unregister_controller(mhi_ctrl);
138 }
139 
140 /* -------------------------------------------------------------------------- */
141 
142 static __inline int
mhi_device_get_sync(struct mhi_device * mhi_dev)143 mhi_device_get_sync(struct mhi_device *mhi_dev)
144 {
145 	/* XXX TODO */
146 	return (-1);
147 }
148 
149 static __inline void
mhi_device_put(struct mhi_device * mhi_dev)150 mhi_device_put(struct mhi_device *mhi_dev)
151 {
152 	/* XXX TODO */
153 }
154 
155 /* -------------------------------------------------------------------------- */
156 
157 static __inline int
mhi_prepare_for_power_up(struct mhi_controller * mhi_ctrl)158 mhi_prepare_for_power_up(struct mhi_controller *mhi_ctrl)
159 {
160 	/* XXX TODO */
161 	return (0);
162 }
163 
164 static __inline int
mhi_sync_power_up(struct mhi_controller * mhi_ctrl)165 mhi_sync_power_up(struct mhi_controller *mhi_ctrl)
166 {
167 	/* XXX TODO */
168 	return (0);
169 }
170 
171 static __inline int
mhi_async_power_up(struct mhi_controller * mhi_ctrl)172 mhi_async_power_up(struct mhi_controller *mhi_ctrl)
173 {
174 	/* XXX TODO */
175 	return (0);
176 }
177 
178 static __inline void
mhi_power_down(struct mhi_controller * mhi_ctrl,bool x)179 mhi_power_down(struct mhi_controller *mhi_ctrl, bool x)
180 {
181 	/* XXX TODO */
182 }
183 
184 static __inline void
mhi_unprepare_after_power_down(struct mhi_controller * mhi_ctrl)185 mhi_unprepare_after_power_down(struct mhi_controller *mhi_ctrl)
186 {
187 	/* XXX TODO */
188 }
189 
190 /* -------------------------------------------------------------------------- */
191 
192 static __inline int
mhi_pm_suspend(struct mhi_controller * mhi_ctrl)193 mhi_pm_suspend(struct mhi_controller *mhi_ctrl)
194 {
195 	/* XXX TODO */
196 	return (0);
197 }
198 
199 static __inline int
mhi_pm_resume(struct mhi_controller * mhi_ctrl)200 mhi_pm_resume(struct mhi_controller *mhi_ctrl)
201 {
202 	/* XXX TODO */
203 	return (0);
204 }
205 
206 static __inline int
mhi_pm_resume_force(struct mhi_controller * mhi_ctrl)207 mhi_pm_resume_force(struct mhi_controller *mhi_ctrl)
208 {
209 	/* XXX TODO */
210 	return (0);
211 }
212 
213 /* -------------------------------------------------------------------------- */
214 
215 static __inline int
mhi_force_rddm_mode(struct mhi_controller * mhi_ctrl)216 mhi_force_rddm_mode(struct mhi_controller *mhi_ctrl)
217 {
218 	/* XXX TODO */
219 	return (0);
220 }
221 
222 #endif	/* _LINUXKPI_LINUX_MHI_H */
223