summaryrefslogtreecommitdiff
path: root/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_shim.c
blob: 33493643b5f8d5035911c1f79f748c47298852d1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
// SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
/* Copyright (c) 2010-2012 Broadcom. All rights reserved. */
#include <linux/module.h>
#include <linux/types.h>
#include <linux/slab.h>
#include <linux/delay.h>

#include "vchiq_if.h"
#include "../vchi/vchi.h"
#include "vchiq.h"

int vchi_queue_kernel_message(unsigned handle, void *data, unsigned int size)
{
	enum vchiq_status status;

	while (1) {
		status = vchiq_queue_kernel_message(handle, data, size);

		/*
		 * vchiq_queue_message() may return VCHIQ_RETRY, so we need to
		 * implement a retry mechanism since this function is supposed
		 * to block until queued
		 */
		if (status != VCHIQ_RETRY)
			break;

		msleep(1);
	}

	return status;
}
EXPORT_SYMBOL(vchi_queue_kernel_message);

/***********************************************************
 * Name: vchi_held_msg_release
 *
 * Arguments:  unsgined handle
 *	       struct vchiq_header *message
 *
 * Description: Routine to release a held message (after it has been read with
 *              vchi_msg_hold)
 *
 * Returns: int - success == 0
 *
 ***********************************************************/
int vchi_held_msg_release(unsigned handle, struct vchiq_header *message)
{
	/*
	 * Convert the service field pointer back to an
	 * unsigned int which is an int.
	 * This pointer is opaque to everything except
	 * vchi_msg_hold which simply upcasted the int
	 * to a pointer.
	 */

	vchiq_release_message(handle, message);

	return 0;
}
EXPORT_SYMBOL(vchi_held_msg_release);

/***********************************************************
 * Name: vchi_msg_hold
 *
 * Arguments:  struct vchi_service *service,
 *             void **data,
 *             unsigned *msg_size,
 *             struct vchiq_header **message
 *
 * Description: Routine to return a pointer to the current message (to allow
 *              in place processing). The message is dequeued - don't forget
 *              to release the message using vchi_held_msg_release when you're
 *              finished.
 *
 * Returns: int - success == 0
 *
 ***********************************************************/
struct vchiq_header *vchi_msg_hold(unsigned handle)
{
	return vchiq_msg_hold(handle);
}
EXPORT_SYMBOL(vchi_msg_hold);

/***********************************************************
 * Name: vchi_initialise
 *
 * Arguments: struct vchiq_instance **instance
 *
 * Description: Initialises the hardware but does not transmit anything
 *              When run as a Host App this will be called twice hence the need
 *              to malloc the state information
 *
 * Returns: 0 if successful, failure otherwise
 *
 ***********************************************************/

int vchi_initialise(struct vchiq_instance **instance)
{
	return vchiq_initialise(instance);
}
EXPORT_SYMBOL(vchi_initialise);

/***********************************************************
 * Name: vchi_connect
 *
 * Arguments: struct vchiq_instance *instance
 *
 * Description: Starts the command service on each connection,
 *              causing INIT messages to be pinged back and forth
 *
 * Returns: 0 if successful, failure otherwise
 *
 ***********************************************************/
int vchi_connect(struct vchiq_instance *instance)
{
	return vchiq_connect(instance);
}
EXPORT_SYMBOL(vchi_connect);

/***********************************************************
 * Name: vchi_disconnect
 *
 * Arguments: struct vchiq_instance *instance
 *
 * Description: Stops the command service on each connection,
 *              causing DE-INIT messages to be pinged back and forth
 *
 * Returns: 0 if successful, failure otherwise
 *
 ***********************************************************/
int vchi_disconnect(struct vchiq_instance *instance)
{
	return vchiq_shutdown(instance);
}
EXPORT_SYMBOL(vchi_disconnect);

/***********************************************************
 * Name: vchi_service_open
 * Name: vchi_service_create
 *
 * Arguments: struct vchiq_instance *instance
 *            struct service_creation *setup,
 *            unsigned *handle
 *
 * Description: Routine to open a service
 *
 * Returns: int - success == 0
 *
 ***********************************************************/

int vchi_service_open(struct vchiq_instance *instance,
		      struct vchiq_service_params *params,
		      unsigned *handle)
{
	return vchiq_open_service(instance, params, handle);
}
EXPORT_SYMBOL(vchi_service_open);

int vchi_service_close(unsigned handle)
{
	return vchiq_close_service(handle);
}
EXPORT_SYMBOL(vchi_service_close);

int vchi_get_peer_version(unsigned handle, short *peer_version)
{
	return vchiq_get_peer_version(handle, peer_version);
}
EXPORT_SYMBOL(vchi_get_peer_version);

/***********************************************************
 * Name: vchi_service_use
 *
 * Arguments: unsigned handle
 *
 * Description: Routine to increment refcount on a service
 *
 * Returns: void
 *
 ***********************************************************/
int vchi_service_use(unsigned handle)
{
	return vchiq_use_service(handle);
}
EXPORT_SYMBOL(vchi_service_use);

/***********************************************************
 * Name: vchi_service_release
 *
 * Arguments: unsigned handle
 *
 * Description: Routine to decrement refcount on a service
 *
 * Returns: void
 *
 ***********************************************************/
int vchi_service_release(unsigned handle)
{
	return vchiq_release_service(handle);
}
EXPORT_SYMBOL(vchi_service_release);