1 // SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
2 /* Copyright (c) 2010-2012 Broadcom. All rights reserved. */
3 #include <linux/module.h>
4 #include <linux/types.h>
5 #include <linux/slab.h>
6 #include <linux/delay.h>
9 #include "../vchi/vchi.h"
11 #include "vchiq_core.h"
13 int vchi_queue_kernel_message(unsigned handle, void *data, unsigned int size)
15 enum vchiq_status status;
18 status = vchiq_queue_kernel_message(handle, data, size);
21 * vchiq_queue_message() may return VCHIQ_RETRY, so we need to
22 * implement a retry mechanism since this function is supposed
23 * to block until queued
25 if (status != VCHIQ_RETRY)
33 EXPORT_SYMBOL(vchi_queue_kernel_message);
35 /***********************************************************
36 * Name: vchi_bulk_queue_receive
38 * Arguments: VCHI_BULK_HANDLE_T handle,
40 * const uint32_t data_size,
41 * enum vchi_flags flags
44 * Description: Routine to setup a rcv buffer
46 * Returns: int32_t - success == 0
48 ***********************************************************/
49 int32_t vchi_bulk_queue_receive(unsigned handle, void *data_dst,
50 uint32_t data_size, enum vchiq_bulk_mode mode,
53 enum vchiq_status status;
56 status = vchiq_bulk_receive(handle, data_dst, data_size,
59 * vchiq_bulk_receive() may return VCHIQ_RETRY, so we need to
60 * implement a retry mechanism since this function is supposed
61 * to block until queued
63 if (status != VCHIQ_RETRY)
71 EXPORT_SYMBOL(vchi_bulk_queue_receive);
73 /***********************************************************
74 * Name: vchi_bulk_queue_transmit
76 * Arguments: VCHI_BULK_HANDLE_T handle,
77 * const void *data_src,
79 * enum vchi_flags flags,
82 * Description: Routine to transmit some data
84 * Returns: int32_t - success == 0
86 ***********************************************************/
87 int32_t vchi_bulk_queue_transmit(unsigned handle, const void *data_src,
88 uint32_t data_size, enum vchiq_bulk_mode mode,
91 enum vchiq_status status;
94 status = vchiq_bulk_transmit(handle, data_src, data_size,
98 * vchiq_bulk_transmit() may return VCHIQ_RETRY, so we need to
99 * implement a retry mechanism since this function is supposed
100 * to block until queued
102 if (status != VCHIQ_RETRY)
110 EXPORT_SYMBOL(vchi_bulk_queue_transmit);
113 /***********************************************************
114 * Name: vchi_held_msg_release
116 * Arguments: unsgined handle
117 * struct vchiq_header *message
119 * Description: Routine to release a held message (after it has been read with
122 * Returns: int32_t - success == 0
124 ***********************************************************/
125 int32_t vchi_held_msg_release(unsigned handle, struct vchiq_header *message)
128 * Convert the service field pointer back to an
129 * unsigned int which is an int.
130 * This pointer is opaque to everything except
131 * vchi_msg_hold which simply upcasted the int
135 vchiq_release_message(handle, message);
139 EXPORT_SYMBOL(vchi_held_msg_release);
141 /***********************************************************
142 * Name: vchi_msg_hold
144 * Arguments: struct vchi_service *service,
146 * uint32_t *msg_size,
147 * struct vchiq_header **message
149 * Description: Routine to return a pointer to the current message (to allow
150 * in place processing). The message is dequeued - don't forget
151 * to release the message using vchi_held_msg_release when you're
154 * Returns: int32_t - success == 0
156 ***********************************************************/
157 int32_t vchi_msg_hold(unsigned handle, void **data, uint32_t *msg_size,
158 struct vchiq_header **message)
160 struct vchiq_header *header;
162 header = vchiq_msg_hold(handle);
166 *data = header->data;
167 *msg_size = header->size;
172 EXPORT_SYMBOL(vchi_msg_hold);
174 /***********************************************************
175 * Name: vchi_initialise
177 * Arguments: struct vchiq_instance **instance
179 * Description: Initialises the hardware but does not transmit anything
180 * When run as a Host App this will be called twice hence the need
181 * to malloc the state information
183 * Returns: 0 if successful, failure otherwise
185 ***********************************************************/
187 int32_t vchi_initialise(struct vchiq_instance **instance)
189 return vchiq_initialise(instance);
191 EXPORT_SYMBOL(vchi_initialise);
193 /***********************************************************
196 * Arguments: struct vchiq_instance *instance
198 * Description: Starts the command service on each connection,
199 * causing INIT messages to be pinged back and forth
201 * Returns: 0 if successful, failure otherwise
203 ***********************************************************/
204 int32_t vchi_connect(struct vchiq_instance *instance)
206 return vchiq_connect(instance);
208 EXPORT_SYMBOL(vchi_connect);
210 /***********************************************************
211 * Name: vchi_disconnect
213 * Arguments: struct vchiq_instance *instance
215 * Description: Stops the command service on each connection,
216 * causing DE-INIT messages to be pinged back and forth
218 * Returns: 0 if successful, failure otherwise
220 ***********************************************************/
221 int32_t vchi_disconnect(struct vchiq_instance *instance)
223 return vchiq_shutdown(instance);
225 EXPORT_SYMBOL(vchi_disconnect);
227 /***********************************************************
228 * Name: vchi_service_open
229 * Name: vchi_service_create
231 * Arguments: struct vchiq_instance *instance
232 * struct service_creation *setup,
235 * Description: Routine to open a service
237 * Returns: int32_t - success == 0
239 ***********************************************************/
241 int32_t vchi_service_open(struct vchiq_instance *instance,
242 struct vchiq_service_params *params,
245 return vchiq_open_service(instance, params, handle);
247 EXPORT_SYMBOL(vchi_service_open);
249 int32_t vchi_service_close(unsigned handle)
251 return vchiq_close_service(handle);
253 EXPORT_SYMBOL(vchi_service_close);
255 int32_t vchi_get_peer_version(unsigned handle, short *peer_version)
257 return vchiq_get_peer_version(handle, peer_version);
259 EXPORT_SYMBOL(vchi_get_peer_version);
261 /***********************************************************
262 * Name: vchi_service_use
264 * Arguments: unsigned handle
266 * Description: Routine to increment refcount on a service
270 ***********************************************************/
271 int32_t vchi_service_use(unsigned handle)
273 return vchiq_use_service(handle);
275 EXPORT_SYMBOL(vchi_service_use);
277 /***********************************************************
278 * Name: vchi_service_release
280 * Arguments: unsigned handle
282 * Description: Routine to decrement refcount on a service
286 ***********************************************************/
287 int32_t vchi_service_release(unsigned handle)
289 return vchiq_release_service(handle);
291 EXPORT_SYMBOL(vchi_service_release);