xref: /freebsd/sys/compat/linuxkpi/common/include/linux/mhi.h (revision e6bfd18d21b225af6a0ed67ceeaf1293b7b9eba5)
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  * $FreeBSD$
28  */
29 
30 #ifndef	_LINUXKPI_LINUX_MHI_H
31 #define	_LINUXKPI_LINUX_MHI_H
32 
33 #include <linux/types.h>
34 
35 /* Modem Host Interface (MHI) */
36 
37 /* XXX FIXME */
38 #define	MHI_DB_BRST_DISABLE	0
39 #define	MHI_ER_CTRL		0
40 
41 enum mhi_callback {
42 	MHI_CB_SYS_ERROR,
43 	MHI_CB_BW_REQ,
44 	MHI_CB_EE_MISSION_MODE,
45 	MHI_CB_EE_RDDM,
46 	MHI_CB_FATAL_ERROR,
47 	MHI_CB_IDLE,
48 	MHI_CB_LPM_ENTER,
49 	MHI_CB_LPM_EXIT,
50 	MHI_CB_PENDING_DATA,
51 };
52 
53 struct mhi_channel_config {
54 	const char		*name;
55 	int	auto_queue, dir, doorbell, doorbell_mode_switch, ee_mask, event_ring, lpm_notify, num, num_elements, offload_channel, pollcfg;
56 };
57 
58 struct mhi_event_config {
59 	int	client_managed, data_type, hardware_event, irq, irq_moderation_ms, mode, num_elements, offload_channel, priority;
60 };
61 
62 struct mhi_device {
63 };
64 
65 struct mhi_controller_config {
66 	struct mhi_channel_config	*ch_cfg;
67 	struct mhi_event_config		*event_cfg;
68 
69 	int	buf_len, max_channels, num_channels, num_events, use_bounce_buf;
70 
71 	uint32_t			timeout_ms;
72 };
73 
74 struct mhi_controller {
75 	struct device			*cntrl_dev;
76 	struct mhi_device		*mhi_dev;
77 	void				*regs;
78 	int				*irq;
79 	const char			*fw_image;
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     struct mhi_controller_config *);
106 void linuxkpi_mhi_unregister_controller(struct mhi_controller *);
107 
108 /* -------------------------------------------------------------------------- */
109 
110 static inline struct mhi_controller *
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
119 mhi_free_controller(struct mhi_controller *mhi_ctrl)
120 {
121 
122 	linuxkpi_mhi_free_controller(mhi_ctrl);
123 }
124 
125 static inline int
126 mhi_register_controller(struct mhi_controller *mhi_ctrl,
127     struct mhi_controller_config *cfg)
128 {
129 
130 	return (linuxkpi_mhi_register_controller(mhi_ctrl, cfg));
131 }
132 
133 static inline void
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
143 mhi_device_get_sync(struct mhi_device *mhi_dev)
144 {
145 	/* XXX TODO */
146 	return (-1);
147 }
148 
149 static __inline void
150 mhi_device_put(struct mhi_device *mhi_dev)
151 {
152 	/* XXX TODO */
153 }
154 
155 /* -------------------------------------------------------------------------- */
156 
157 static __inline int
158 mhi_prepare_for_power_up(struct mhi_controller *mhi_ctrl)
159 {
160 	/* XXX TODO */
161 	return (0);
162 }
163 
164 static __inline int
165 mhi_sync_power_up(struct mhi_controller *mhi_ctrl)
166 {
167 	/* XXX TODO */
168 	return (0);
169 }
170 
171 static __inline int
172 mhi_async_power_up(struct mhi_controller *mhi_ctrl)
173 {
174 	/* XXX TODO */
175 	return (0);
176 }
177 
178 static __inline void
179 mhi_power_down(struct mhi_controller *mhi_ctrl, bool x)
180 {
181 	/* XXX TODO */
182 }
183 
184 static __inline void
185 mhi_unprepare_after_power_down(struct mhi_controller *mhi_ctrl)
186 {
187 	/* XXX TODO */
188 }
189 
190 /* -------------------------------------------------------------------------- */
191 
192 static __inline int
193 mhi_pm_suspend(struct mhi_controller *mhi_ctrl)
194 {
195 	/* XXX TODO */
196 	return (0);
197 }
198 
199 static __inline int
200 mhi_pm_resume_force(struct mhi_controller *mhi_ctrl)
201 {
202 	/* XXX TODO */
203 	return (0);
204 }
205 
206 /* -------------------------------------------------------------------------- */
207 
208 static __inline int
209 mhi_force_rddm_mode(struct mhi_controller *mhi_ctrl)
210 {
211 	/* XXX TODO */
212 	return (0);
213 }
214 
215 #endif	/* _LINUXKPI_LINUX_MHI_H */
216