blob: 28841a9198ff06da92287fc03feb3be4a1d1eb6d [file] [log] [blame]
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001/** include/asm-arm/arch-msm/msm_rpcrouter.h
2 *
3 * Copyright (C) 2007 Google, Inc.
4 * Copyright (c) 2007-2011, Code Aurora Forum. All rights reserved.
5 * Author: San Mehat <san@android.com>
6 *
7 * This software is licensed under the terms of the GNU General Public
8 * License version 2, as published by the Free Software Foundation, and
9 * may be copied, distributed, and modified under those terms.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 */
17
18#ifndef __ASM__ARCH_MSM_RPCROUTER_H
19#define __ASM__ARCH_MSM_RPCROUTER_H
20
21#include <linux/types.h>
22#include <linux/list.h>
23#include <linux/platform_device.h>
24
25/* RPC API version structure
26 * Version bit 31 : 1->hashkey versioning,
27 * 0->major-minor (backward compatible) versioning
28 * hashkey versioning:
29 * Version bits 31-0 hashkey
30 * major-minor (backward compatible) versioning
31 * Version bits 30-28 reserved (no match)
32 * Version bits 27-16 major (must match)
33 * Version bits 15-0 minor (greater or equal)
34 */
35#define RPC_VERSION_MODE_MASK 0x80000000
36#define RPC_VERSION_MAJOR_MASK 0x0fff0000
37#define RPC_VERSION_MINOR_MASK 0x0000ffff
38
39/* callback ID for NULL callback function is -1 */
40#define MSM_RPC_CLIENT_NULL_CB_ID 0xffffffff
41
42struct msm_rpc_endpoint;
43
44struct rpcsvr_platform_device
45{
46 struct platform_device base;
47 uint32_t prog;
48 uint32_t vers;
49};
50
51#define RPC_DATA_IN 0
52/*
53 * Structures for sending / receiving direct RPC requests
54 * XXX: Any cred/verif lengths > 0 not supported
55 */
56
57struct rpc_request_hdr
58{
59 uint32_t xid;
60 uint32_t type; /* 0 */
61 uint32_t rpc_vers; /* 2 */
62 uint32_t prog;
63 uint32_t vers;
64 uint32_t procedure;
65 uint32_t cred_flavor;
66 uint32_t cred_length;
67 uint32_t verf_flavor;
68 uint32_t verf_length;
69};
70
71typedef struct
72{
73 uint32_t low;
74 uint32_t high;
75} rpc_reply_progmismatch_data;
76
77typedef struct
78{
79} rpc_denied_reply_hdr;
80
81typedef struct
82{
83 uint32_t verf_flavor;
84 uint32_t verf_length;
85 uint32_t accept_stat;
86#define RPC_ACCEPTSTAT_SUCCESS 0
87#define RPC_ACCEPTSTAT_PROG_UNAVAIL 1
88#define RPC_ACCEPTSTAT_PROG_MISMATCH 2
89#define RPC_ACCEPTSTAT_PROC_UNAVAIL 3
90#define RPC_ACCEPTSTAT_GARBAGE_ARGS 4
91#define RPC_ACCEPTSTAT_SYSTEM_ERR 5
92#define RPC_ACCEPTSTAT_PROG_LOCKED 6
93 /*
94 * Following data is dependant on accept_stat
95 * If ACCEPTSTAT == PROG_MISMATCH then there is a
96 * 'rpc_reply_progmismatch_data' structure following the header.
97 * Otherwise the data is procedure specific
98 */
99} rpc_accepted_reply_hdr;
100
101struct rpc_reply_hdr
102{
103 uint32_t xid;
104 uint32_t type;
105 uint32_t reply_stat;
106#define RPCMSG_REPLYSTAT_ACCEPTED 0
107#define RPCMSG_REPLYSTAT_DENIED 1
108 union {
109 rpc_accepted_reply_hdr acc_hdr;
110 rpc_denied_reply_hdr dny_hdr;
111 } data;
112};
113
114struct rpc_board_dev {
115 uint32_t prog;
116 struct platform_device pdev;
117};
118
119/* flags for msm_rpc_connect() */
120#define MSM_RPC_UNINTERRUPTIBLE 0x0001
121
122/* use IS_ERR() to check for failure */
123struct msm_rpc_endpoint *msm_rpc_open(void);
124/* Connect with the specified server version */
125struct msm_rpc_endpoint *msm_rpc_connect(uint32_t prog, uint32_t vers, unsigned flags);
126/* Connect with a compatible server version */
127struct msm_rpc_endpoint *msm_rpc_connect_compatible(uint32_t prog,
128 uint32_t vers, unsigned flags);
129/* check if server version can handle client requested version */
130int msm_rpc_is_compatible_version(uint32_t server_version,
131 uint32_t client_version);
132
133int msm_rpc_close(struct msm_rpc_endpoint *ept);
134int msm_rpc_write(struct msm_rpc_endpoint *ept,
135 void *data, int len);
136int msm_rpc_read(struct msm_rpc_endpoint *ept,
137 void **data, unsigned len, long timeout);
138void msm_rpc_read_wakeup(struct msm_rpc_endpoint *ept);
139void msm_rpc_setup_req(struct rpc_request_hdr *hdr,
140 uint32_t prog, uint32_t vers, uint32_t proc);
141int msm_rpc_register_server(struct msm_rpc_endpoint *ept,
142 uint32_t prog, uint32_t vers);
143int msm_rpc_unregister_server(struct msm_rpc_endpoint *ept,
144 uint32_t prog, uint32_t vers);
145
146int msm_rpc_add_board_dev(struct rpc_board_dev *board_dev, int num);
147
148int msm_rpc_clear_netreset(struct msm_rpc_endpoint *ept);
149
150int msm_rpc_get_curr_pkt_size(struct msm_rpc_endpoint *ept);
151/* simple blocking rpc call
152 *
153 * request is mandatory and must have a rpc_request_hdr
154 * at the start. The header will be filled out for you.
155 *
156 * reply provides a buffer for replies of reply_max_size
157 */
158int msm_rpc_call_reply(struct msm_rpc_endpoint *ept, uint32_t proc,
159 void *request, int request_size,
160 void *reply, int reply_max_size,
161 long timeout);
162int msm_rpc_call(struct msm_rpc_endpoint *ept, uint32_t proc,
163 void *request, int request_size,
164 long timeout);
165
166struct msm_rpc_xdr {
167 void *in_buf;
168 uint32_t in_size;
169 uint32_t in_index;
170 wait_queue_head_t in_buf_wait_q;
171
172 void *out_buf;
173 uint32_t out_size;
174 uint32_t out_index;
175 struct mutex out_lock;
176
177 struct msm_rpc_endpoint *ept;
178};
179
180int xdr_send_int8(struct msm_rpc_xdr *xdr, const int8_t *value);
181int xdr_send_uint8(struct msm_rpc_xdr *xdr, const uint8_t *value);
182int xdr_send_int16(struct msm_rpc_xdr *xdr, const int16_t *value);
183int xdr_send_uint16(struct msm_rpc_xdr *xdr, const uint16_t *value);
184int xdr_send_int32(struct msm_rpc_xdr *xdr, const int32_t *value);
185int xdr_send_uint32(struct msm_rpc_xdr *xdr, const uint32_t *value);
186int xdr_send_bytes(struct msm_rpc_xdr *xdr, const void **data, uint32_t *size);
187
188int xdr_recv_int8(struct msm_rpc_xdr *xdr, int8_t *value);
189int xdr_recv_uint8(struct msm_rpc_xdr *xdr, uint8_t *value);
190int xdr_recv_int16(struct msm_rpc_xdr *xdr, int16_t *value);
191int xdr_recv_uint16(struct msm_rpc_xdr *xdr, uint16_t *value);
192int xdr_recv_int32(struct msm_rpc_xdr *xdr, int32_t *value);
193int xdr_recv_uint32(struct msm_rpc_xdr *xdr, uint32_t *value);
194int xdr_recv_bytes(struct msm_rpc_xdr *xdr, void **data, uint32_t *size);
195
196struct msm_rpc_server
197{
198 struct list_head list;
199 uint32_t flags;
200
201 uint32_t prog;
202 uint32_t vers;
203
204 struct mutex cb_req_lock;
205
206 struct msm_rpc_endpoint *cb_ept;
207
208 struct msm_rpc_xdr cb_xdr;
209
210 uint32_t version;
211
212 int (*rpc_call)(struct msm_rpc_server *server,
213 struct rpc_request_hdr *req, unsigned len);
214
215 int (*rpc_call2)(struct msm_rpc_server *server,
216 struct rpc_request_hdr *req,
217 struct msm_rpc_xdr *xdr);
218};
219
220int msm_rpc_create_server(struct msm_rpc_server *server);
221int msm_rpc_create_server2(struct msm_rpc_server *server);
222
223#define MSM_RPC_MSGSIZE_MAX 8192
224
225struct msm_rpc_client;
226
227struct msm_rpc_client {
228 struct task_struct *read_thread;
229 struct task_struct *cb_thread;
230
231 struct msm_rpc_endpoint *ept;
232 wait_queue_head_t reply_wait;
233
234 uint32_t prog, ver;
235
236 void *buf;
237
238 struct msm_rpc_xdr xdr;
239 struct msm_rpc_xdr cb_xdr;
240
241 uint32_t version;
242
243 int (*cb_func)(struct msm_rpc_client *, void *, int);
244 int (*cb_func2)(struct msm_rpc_client *, struct rpc_request_hdr *req,
245 struct msm_rpc_xdr *);
246 void *cb_buf;
247 int cb_size;
248
249 struct list_head cb_item_list;
250 struct mutex cb_item_list_lock;
251
252 wait_queue_head_t cb_wait;
253 int cb_avail;
254
255 atomic_t next_cb_id;
Karthikeyan Ramasubramanianf23a2312011-08-23 10:27:32 -0600256 spinlock_t cb_list_lock;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700257 struct list_head cb_list;
258
259 uint32_t exit_flag;
260 struct completion complete;
261 struct completion cb_complete;
262
263 struct mutex req_lock;
264
265 void (*cb_restart_teardown)(struct msm_rpc_client *client);
266 void (*cb_restart_setup)(struct msm_rpc_client *client);
267 int in_reset;
268};
269
270struct msm_rpc_client_info {
271 uint32_t pid;
272 uint32_t cid;
273 uint32_t prog;
274 uint32_t vers;
275};
276
277
278int msm_rpc_client_in_reset(struct msm_rpc_client *client);
279
280struct msm_rpc_client *msm_rpc_register_client(
281 const char *name,
282 uint32_t prog, uint32_t ver,
283 uint32_t create_cb_thread,
284 int (*cb_func)(struct msm_rpc_client *, void *, int));
285
286struct msm_rpc_client *msm_rpc_register_client2(
287 const char *name,
288 uint32_t prog, uint32_t ver,
289 uint32_t create_cb_thread,
290 int (*cb_func)(struct msm_rpc_client *, struct rpc_request_hdr *req,
291 struct msm_rpc_xdr *xdr));
292
293int msm_rpc_unregister_client(struct msm_rpc_client *client);
294
295int msm_rpc_client_req(struct msm_rpc_client *client, uint32_t proc,
296 int (*arg_func)(struct msm_rpc_client *,
297 void *, void *), void *arg_data,
298 int (*result_func)(struct msm_rpc_client *,
299 void *, void *), void *result_data,
300 long timeout);
301
302int msm_rpc_client_req2(struct msm_rpc_client *client, uint32_t proc,
303 int (*arg_func)(struct msm_rpc_client *,
304 struct msm_rpc_xdr *, void *),
305 void *arg_data,
306 int (*result_func)(struct msm_rpc_client *,
307 struct msm_rpc_xdr *, void *),
308 void *result_data,
309 long timeout);
310
311int msm_rpc_register_reset_callbacks(
312 struct msm_rpc_client *client,
313 void (*teardown)(struct msm_rpc_client *client),
314 void (*setup)(struct msm_rpc_client *client)
315 );
316
317void *msm_rpc_start_accepted_reply(struct msm_rpc_client *client,
318 uint32_t xid, uint32_t accept_status);
319
320int msm_rpc_send_accepted_reply(struct msm_rpc_client *client, uint32_t size);
321
322void *msm_rpc_server_start_accepted_reply(struct msm_rpc_server *server,
323 uint32_t xid, uint32_t accept_status);
324
325int msm_rpc_server_send_accepted_reply(struct msm_rpc_server *server,
326 uint32_t size);
327
328int msm_rpc_add_cb_func(struct msm_rpc_client *client, void *cb_func);
329
330void *msm_rpc_get_cb_func(struct msm_rpc_client *client, uint32_t cb_id);
331
332void msm_rpc_remove_cb_func(struct msm_rpc_client *client, void *cb_func);
333
334int msm_rpc_server_cb_req(struct msm_rpc_server *server,
335 struct msm_rpc_client_info *clnt_info,
336 uint32_t cb_proc,
337 int (*arg_func)(struct msm_rpc_server *server,
338 void *buf, void *data),
339 void *arg_data,
340 int (*ret_func)(struct msm_rpc_server *server,
341 void *buf, void *data),
342 void *ret_data, long timeout);
343
344int msm_rpc_server_cb_req2(struct msm_rpc_server *server,
345 struct msm_rpc_client_info *clnt_info,
346 uint32_t cb_proc,
347 int (*arg_func)(struct msm_rpc_server *server,
348 struct msm_rpc_xdr *xdr, void *data),
349 void *arg_data,
350 int (*ret_func)(struct msm_rpc_server *server,
351 struct msm_rpc_xdr *xdr, void *data),
352 void *ret_data, long timeout);
353
354void msm_rpc_server_get_requesting_client(
355 struct msm_rpc_client_info *clnt_info);
356
357int xdr_send_pointer(struct msm_rpc_xdr *xdr, void **obj,
358 uint32_t obj_size, void *xdr_op);
359
360int xdr_recv_pointer(struct msm_rpc_xdr *xdr, void **obj,
361 uint32_t obj_size, void *xdr_op);
362
363int xdr_send_array(struct msm_rpc_xdr *xdr, void **addr, uint32_t *size,
364 uint32_t maxsize, uint32_t elm_size, void *xdr_op);
365
366int xdr_recv_array(struct msm_rpc_xdr *xdr, void **addr, uint32_t *size,
367 uint32_t maxsize, uint32_t elm_size, void *xdr_op);
368
369int xdr_recv_req(struct msm_rpc_xdr *xdr, struct rpc_request_hdr *req);
370int xdr_recv_reply(struct msm_rpc_xdr *xdr, struct rpc_reply_hdr *reply);
371int xdr_start_request(struct msm_rpc_xdr *xdr, uint32_t prog,
372 uint32_t ver, uint32_t proc);
373int xdr_start_accepted_reply(struct msm_rpc_xdr *xdr, uint32_t accept_status);
374int xdr_send_msg(struct msm_rpc_xdr *xdr);
375
376#endif