xref: /freebsd/sys/compat/linuxkpi/common/include/linux/soc/qcom/qmi.h (revision 54b955f4df5e76b5679ba7f3eb6bb2d5fc62923d)
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_SOC_QCOM_QMI_H
31 #define	_LINUXKPI_LINUX_SOC_QCOM_QMI_H
32 
33 /* QMI (Qualcomm MSM Interface) */
34 
35 #include <linux/qrtr.h>
36 
37 enum soc_qcom_qmi_data_type {
38 	QMI_EOTI,
39 	QMI_DATA_LEN,
40 	QMI_OPT_FLAG,
41 	QMI_UNSIGNED_1_BYTE,
42 	QMI_UNSIGNED_2_BYTE,
43 	QMI_UNSIGNED_4_BYTE,
44 	QMI_UNSIGNED_8_BYTE,
45 	QMI_SIGNED_4_BYTE_ENUM,
46 	QMI_STRUCT,
47 	QMI_STRING,
48 };
49 
50 #define	QMI_RESULT_SUCCESS_V01	__LINE__
51 #define	QMI_INDICATION		__LINE__
52 
53 struct qmi_handle;
54 
55 enum soc_qcom_qmi_array_type {
56 	NO_ARRAY,
57 	VAR_LEN_ARRAY,
58 };
59 
60 /* Should this become an enum? */
61 #define	QMI_COMMON_TLV_TYPE			0
62 
63 struct qmi_elem_info {
64 	enum soc_qcom_qmi_data_type		data_type;
65 	uint32_t				elem_len;
66 	uint32_t				elem_size;
67 	enum soc_qcom_qmi_array_type		array_type;
68 	uint8_t					tlv_type;
69 	uint32_t				offset;
70 	const struct qmi_elem_info		*ei_array;
71 };
72 
73 struct qmi_response_type_v01 {
74 	uint16_t				result;
75 	uint16_t				error;
76 };
77 
78 struct qmi_txn {
79 };
80 
81 struct qmi_service {
82 	uint32_t				node;
83 	uint32_t				port;
84 };
85 
86 struct qmi_msg_handler {
87 	uint32_t				type;
88 	uint32_t				msg_id;
89 	const struct qmi_elem_info		*ei;
90 	size_t					decoded_size;
91 	void	(*fn)(struct qmi_handle *, struct sockaddr_qrtr *, struct qmi_txn *, const void *);
92 };
93 
94 struct qmi_ops {
95 	int	(*new_server)(struct qmi_handle *, struct qmi_service *);
96 	void	(*del_server)(struct qmi_handle *, struct qmi_service *);
97 };
98 
99 struct qmi_handle {
100 	int				sock;
101 
102 	const struct qmi_msg_handler	*handler;
103 	struct qmi_ops			ops;
104 };
105 
106 
107 /* XXX-TODO need implementation somewhere... it is not in ath1xk* */
108 extern struct qmi_elem_info qmi_response_type_v01_ei[];
109 
110 static inline int
111 qmi_handle_init(struct qmi_handle *handle, size_t resp_len_max,
112     const struct qmi_ops *ops, const struct qmi_msg_handler *handler)
113 {
114 
115 	handle->handler = handler;
116 	if (ops != NULL)
117 		handle->ops = *ops;
118 
119         /* We will find out what else to do here. */
120 	/* XXX TODO */
121 
122 	return (0);
123 }
124 
125 static __inline int
126 qmi_add_lookup(struct qmi_handle *handle, uint32_t service, uint32_t version,
127     uint32_t service_ins_id)
128 {
129 
130 	/* XXX TODO */
131 	return (0);
132 }
133 
134 static __inline void
135 qmi_handle_release(struct qmi_handle *handle)
136 {
137 
138 	/* XXX TODO */
139 }
140 
141 static __inline int
142 qmi_send_request(struct qmi_handle *handle, void *x, struct qmi_txn *txn,
143     uint32_t msd_id, size_t len, const struct qmi_elem_info *ei, void *req)
144 {
145 
146 	/* XXX TODO */
147 	return (-ENXIO);
148 }
149 
150 static __inline void
151 qmi_txn_cancel(struct qmi_txn *txn)
152 {
153 
154 	/* XXX TODO */
155 }
156 
157 static __inline int
158 qmi_txn_init(struct qmi_handle *handle, struct qmi_txn *txn,
159     const struct qmi_elem_info *ei, void *resp)
160 {
161 
162 	/* XXX TODO */
163 	return (-ENXIO);
164 }
165 
166 static __inline int
167 qmi_txn_wait(struct qmi_txn *txn, uint64_t jiffies)
168 {
169 
170 	/* XXX TODO */
171 	return (-ENXIO);
172 }
173 
174 #endif	/* _LINUXKPI_LINUX_SOC_QCOM_QMI_H */
175