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