1 /**
2 * Copyright (c) 2010-2012 Broadcom. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions, and the following disclaimer,
9 * without modification.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. The names of the above-listed copyright holders may not be used
14 * to endorse or promote products derived from this software without
15 * specific prior written permission.
16 *
17 * ALTERNATIVELY, this software may be distributed under the terms of the
18 * GNU General Public License ("GPL") version 2, as published by the Free
19 * Software Foundation.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
22 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
23 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
25 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
26 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
27 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
28 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
29 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 */
33
34 #ifndef VCHIQ_CORE_H
35 #define VCHIQ_CORE_H
36
37 #include <interface/compat/vchi_bsd.h>
38 #include <interface/compat/list.h>
39
40 #include "vchiq_cfg.h"
41
42 #include "vchiq.h"
43
44 /* Run time control of log level, based on KERN_XXX level. */
45 #ifndef VCHIQ_LOG_DEFAULT
46 #define VCHIQ_LOG_DEFAULT 4
47 #endif
48 #define VCHIQ_LOG_ERROR 3
49 #define VCHIQ_LOG_WARNING 4
50 #define VCHIQ_LOG_INFO 6
51 #define VCHIQ_LOG_TRACE 7
52
53 #define VCHIQ_LOG_PREFIX "vchiq: "
54
55 #ifndef vchiq_log_error
56 #define vchiq_log_error(cat, fmt, ...) \
57 do { if (cat >= VCHIQ_LOG_ERROR) \
58 printf(VCHIQ_LOG_PREFIX fmt "\n", ##__VA_ARGS__); } while (0)
59 #endif
60 #ifndef vchiq_log_warning
61 #define vchiq_log_warning(cat, fmt, ...) \
62 do { if (cat >= VCHIQ_LOG_WARNING) \
63 printf(VCHIQ_LOG_PREFIX fmt "\n", ##__VA_ARGS__); } while (0)
64 #endif
65 #ifndef vchiq_log_info
66 #define vchiq_log_info(cat, fmt, ...) \
67 do { if (cat >= VCHIQ_LOG_INFO) \
68 printf(VCHIQ_LOG_PREFIX fmt "\n", ##__VA_ARGS__); } while (0)
69 #endif
70 #ifndef vchiq_log_trace
71 #define vchiq_log_trace(cat, fmt, ...) \
72 do { if (cat >= VCHIQ_LOG_TRACE) \
73 printf(VCHIQ_LOG_PREFIX fmt "\n", ##__VA_ARGS__); } while (0)
74 #endif
75
76 #define vchiq_loud_error(...) \
77 vchiq_log_error(vchiq_core_log_level, "===== " __VA_ARGS__)
78
79 #ifndef vchiq_static_assert
80 #define vchiq_static_assert(cond) __attribute__((unused)) \
81 extern int vchiq_static_assert[(cond) ? 1 : -1]
82 #endif
83
84 #define IS_POW2(x) (x && ((x & (x - 1)) == 0))
85
86 /* Ensure that the slot size and maximum number of slots are powers of 2 */
87 vchiq_static_assert(IS_POW2(VCHIQ_SLOT_SIZE));
88 vchiq_static_assert(IS_POW2(VCHIQ_MAX_SLOTS));
89 vchiq_static_assert(IS_POW2(VCHIQ_MAX_SLOTS_PER_SIDE));
90
91 #define VCHIQ_SLOT_MASK (VCHIQ_SLOT_SIZE - 1)
92 #define VCHIQ_SLOT_QUEUE_MASK (VCHIQ_MAX_SLOTS_PER_SIDE - 1)
93 #define VCHIQ_SLOT_ZERO_SLOTS ((sizeof(VCHIQ_SLOT_ZERO_T) + \
94 VCHIQ_SLOT_SIZE - 1) / VCHIQ_SLOT_SIZE)
95
96 #define VCHIQ_MSG_PADDING 0 /* - */
97 #define VCHIQ_MSG_CONNECT 1 /* - */
98 #define VCHIQ_MSG_OPEN 2 /* + (srcport, -), fourcc, client_id */
99 #define VCHIQ_MSG_OPENACK 3 /* + (srcport, dstport) */
100 #define VCHIQ_MSG_CLOSE 4 /* + (srcport, dstport) */
101 #define VCHIQ_MSG_DATA 5 /* + (srcport, dstport) */
102 #define VCHIQ_MSG_BULK_RX 6 /* + (srcport, dstport), data, size */
103 #define VCHIQ_MSG_BULK_TX 7 /* + (srcport, dstport), data, size */
104 #define VCHIQ_MSG_BULK_RX_DONE 8 /* + (srcport, dstport), actual */
105 #define VCHIQ_MSG_BULK_TX_DONE 9 /* + (srcport, dstport), actual */
106 #define VCHIQ_MSG_PAUSE 10 /* - */
107 #define VCHIQ_MSG_RESUME 11 /* - */
108 #define VCHIQ_MSG_REMOTE_USE 12 /* - */
109 #define VCHIQ_MSG_REMOTE_RELEASE 13 /* - */
110 #define VCHIQ_MSG_REMOTE_USE_ACTIVE 14 /* - */
111
112 #define VCHIQ_PORT_MAX (VCHIQ_MAX_SERVICES - 1)
113 #define VCHIQ_PORT_FREE 0x1000
114 #define VCHIQ_PORT_IS_VALID(port) (port < VCHIQ_PORT_FREE)
115 #define VCHIQ_MAKE_MSG(type, srcport, dstport) \
116 ((type<<24) | (srcport<<12) | (dstport<<0))
117 #define VCHIQ_MSG_TYPE(msgid) ((unsigned int)msgid >> 24)
118 #define VCHIQ_MSG_SRCPORT(msgid) \
119 (unsigned short)(((unsigned int)msgid >> 12) & 0xfff)
120 #define VCHIQ_MSG_DSTPORT(msgid) \
121 ((unsigned short)msgid & 0xfff)
122
123 #define VCHIQ_FOURCC_AS_4CHARS(fourcc) \
124 ((fourcc) >> 24) & 0xff, \
125 ((fourcc) >> 16) & 0xff, \
126 ((fourcc) >> 8) & 0xff, \
127 (fourcc) & 0xff
128
129 /* Ensure the fields are wide enough */
130 vchiq_static_assert(VCHIQ_MSG_SRCPORT(VCHIQ_MAKE_MSG(0, 0, VCHIQ_PORT_MAX))
131 == 0);
132 vchiq_static_assert(VCHIQ_MSG_TYPE(VCHIQ_MAKE_MSG(0, VCHIQ_PORT_MAX, 0)) == 0);
133 vchiq_static_assert((unsigned int)VCHIQ_PORT_MAX <
134 (unsigned int)VCHIQ_PORT_FREE);
135
136 #define VCHIQ_MSGID_PADDING VCHIQ_MAKE_MSG(VCHIQ_MSG_PADDING, 0, 0)
137 #define VCHIQ_MSGID_CLAIMED 0x40000000
138
139 #define VCHIQ_FOURCC_INVALID 0x00000000
140 #define VCHIQ_FOURCC_IS_LEGAL(fourcc) (fourcc != VCHIQ_FOURCC_INVALID)
141
142 #define VCHIQ_BULK_ACTUAL_ABORTED -1
143
144 typedef uint32_t VCHI_BITSET_T;
145
146 vchiq_static_assert((sizeof(VCHI_BITSET_T) * 8) == 32);
147
148 #define VCHI_BITSET_SIZE(b) ((b + 31) >> 5)
149 #define VCHI_BITSET_WORD(b) (b >> 5)
150 #define VCHI_BITSET_BIT(b) (1 << (b & 31))
151 #define VCHI_BITSET_ZERO(bs) memset(bs, 0, sizeof(bs))
152 #define VCHI_BITSET_IS_SET(bs, b) (bs[VCHI_BITSET_WORD(b)] & VCHI_BITSET_BIT(b))
153 #define VCHI_BITSET_SET(bs, b) (bs[VCHI_BITSET_WORD(b)] |= VCHI_BITSET_BIT(b))
154 #define VCHI_BITSET_CLR(bs, b) (bs[VCHI_BITSET_WORD(b)] &= ~VCHI_BITSET_BIT(b))
155
156 #if VCHIQ_ENABLE_STATS
157 #define VCHIQ_STATS_INC(state, stat) (state->stats. stat++)
158 #define VCHIQ_SERVICE_STATS_INC(service, stat) (service->stats. stat++)
159 #define VCHIQ_SERVICE_STATS_ADD(service, stat, addend) \
160 (service->stats. stat += addend)
161 #else
162 #define VCHIQ_STATS_INC(state, stat) ((void)0)
163 #define VCHIQ_SERVICE_STATS_INC(service, stat) ((void)0)
164 #define VCHIQ_SERVICE_STATS_ADD(service, stat, addend) ((void)0)
165 #endif
166
167 enum {
168 DEBUG_ENTRIES,
169 #if VCHIQ_ENABLE_DEBUG
170 DEBUG_SLOT_HANDLER_COUNT,
171 DEBUG_SLOT_HANDLER_LINE,
172 DEBUG_PARSE_LINE,
173 DEBUG_PARSE_HEADER,
174 DEBUG_PARSE_MSGID,
175 DEBUG_AWAIT_COMPLETION_LINE,
176 DEBUG_DEQUEUE_MESSAGE_LINE,
177 DEBUG_SERVICE_CALLBACK_LINE,
178 DEBUG_MSG_QUEUE_FULL_COUNT,
179 DEBUG_COMPLETION_QUEUE_FULL_COUNT,
180 #endif
181 DEBUG_MAX
182 };
183
184 #if VCHIQ_ENABLE_DEBUG
185
186 #define DEBUG_INITIALISE(local) int *debug_ptr = (local)->debug;
187 #if defined(__aarch64__)
188 #define DEBUG_TRACE(d) \
189 do { debug_ptr[DEBUG_ ## d] = __LINE__; dsb(sy); } while (0)
190 #define DEBUG_VALUE(d, v) \
191 do { debug_ptr[DEBUG_ ## d] = (v); dsb(sy); } while (0)
192 #define DEBUG_COUNT(d) \
193 do { debug_ptr[DEBUG_ ## d]++; dsb(sy); } while (0)
194 #else
195 #define DEBUG_TRACE(d) \
196 do { debug_ptr[DEBUG_ ## d] = __LINE__; dsb(); } while (0)
197 #define DEBUG_VALUE(d, v) \
198 do { debug_ptr[DEBUG_ ## d] = (v); dsb(); } while (0)
199 #define DEBUG_COUNT(d) \
200 do { debug_ptr[DEBUG_ ## d]++; dsb(); } while (0)
201 #endif
202
203 #else /* VCHIQ_ENABLE_DEBUG */
204
205 #define DEBUG_INITIALISE(local)
206 #define DEBUG_TRACE(d)
207 #define DEBUG_VALUE(d, v)
208 #define DEBUG_COUNT(d)
209
210 #endif /* VCHIQ_ENABLE_DEBUG */
211
212 typedef enum {
213 VCHIQ_CONNSTATE_DISCONNECTED,
214 VCHIQ_CONNSTATE_CONNECTING,
215 VCHIQ_CONNSTATE_CONNECTED,
216 VCHIQ_CONNSTATE_PAUSING,
217 VCHIQ_CONNSTATE_PAUSE_SENT,
218 VCHIQ_CONNSTATE_PAUSED,
219 VCHIQ_CONNSTATE_RESUMING,
220 VCHIQ_CONNSTATE_PAUSE_TIMEOUT,
221 VCHIQ_CONNSTATE_RESUME_TIMEOUT
222 } VCHIQ_CONNSTATE_T;
223
224 enum {
225 VCHIQ_SRVSTATE_FREE,
226 VCHIQ_SRVSTATE_HIDDEN,
227 VCHIQ_SRVSTATE_LISTENING,
228 VCHIQ_SRVSTATE_OPENING,
229 VCHIQ_SRVSTATE_OPEN,
230 VCHIQ_SRVSTATE_OPENSYNC,
231 VCHIQ_SRVSTATE_CLOSESENT,
232 VCHIQ_SRVSTATE_CLOSERECVD,
233 VCHIQ_SRVSTATE_CLOSEWAIT,
234 VCHIQ_SRVSTATE_CLOSED
235 };
236
237 enum {
238 VCHIQ_POLL_TERMINATE,
239 VCHIQ_POLL_REMOVE,
240 VCHIQ_POLL_TXNOTIFY,
241 VCHIQ_POLL_RXNOTIFY,
242 VCHIQ_POLL_COUNT
243 };
244
245 typedef enum {
246 VCHIQ_BULK_TRANSMIT,
247 VCHIQ_BULK_RECEIVE
248 } VCHIQ_BULK_DIR_T;
249
250 typedef void (*VCHIQ_USERDATA_TERM_T)(void *userdata);
251
252 typedef struct vchiq_bulk_struct {
253 short mode;
254 short dir;
255 void *userdata;
256 VCHI_MEM_HANDLE_T handle;
257 void *data;
258 int size;
259 void *remote_data;
260 int remote_size;
261 int actual;
262 } VCHIQ_BULK_T;
263
264 typedef struct vchiq_bulk_queue_struct {
265 int local_insert; /* Where to insert the next local bulk */
266 int remote_insert; /* Where to insert the next remote bulk (master) */
267 int process; /* Bulk to transfer next */
268 int remote_notify; /* Bulk to notify the remote client of next (mstr) */
269 int remove; /* Bulk to notify the local client of, and remove,
270 ** next */
271 VCHIQ_BULK_T bulks[VCHIQ_NUM_SERVICE_BULKS];
272 } VCHIQ_BULK_QUEUE_T;
273
274 typedef struct remote_event_struct {
275 int armed;
276 int fired;
277 uint32_t event;
278 } REMOTE_EVENT_T;
279
280 typedef struct opaque_platform_state_t *VCHIQ_PLATFORM_STATE_T;
281
282 typedef struct vchiq_state_struct VCHIQ_STATE_T;
283
284 typedef struct vchiq_slot_struct {
285 char data[VCHIQ_SLOT_SIZE];
286 } VCHIQ_SLOT_T;
287
288 typedef struct vchiq_slot_info_struct {
289 /* Use two counters rather than one to avoid the need for a mutex. */
290 short use_count;
291 short release_count;
292 } VCHIQ_SLOT_INFO_T;
293
294 typedef struct vchiq_service_struct {
295 VCHIQ_SERVICE_BASE_T base;
296 VCHIQ_SERVICE_HANDLE_T handle;
297 unsigned int ref_count;
298 int srvstate;
299 VCHIQ_USERDATA_TERM_T userdata_term;
300 unsigned int localport;
301 unsigned int remoteport;
302 int public_fourcc;
303 int client_id;
304 char auto_close;
305 char sync;
306 char closing;
307 char trace;
308 atomic_t poll_flags;
309 short version;
310 short version_min;
311 short peer_version;
312
313 VCHIQ_STATE_T *state;
314 VCHIQ_INSTANCE_T instance;
315
316 int service_use_count;
317
318 VCHIQ_BULK_QUEUE_T bulk_tx;
319 VCHIQ_BULK_QUEUE_T bulk_rx;
320
321 struct semaphore remove_event;
322 struct semaphore bulk_remove_event;
323 struct mutex bulk_mutex;
324
325 struct service_stats_struct {
326 int quota_stalls;
327 int slot_stalls;
328 int bulk_stalls;
329 int error_count;
330 int ctrl_tx_count;
331 int ctrl_rx_count;
332 int bulk_tx_count;
333 int bulk_rx_count;
334 int bulk_aborted_count;
335 uint64_t ctrl_tx_bytes;
336 uint64_t ctrl_rx_bytes;
337 uint64_t bulk_tx_bytes;
338 uint64_t bulk_rx_bytes;
339 } stats;
340 } VCHIQ_SERVICE_T;
341
342 /* The quota information is outside VCHIQ_SERVICE_T so that it can be
343 statically allocated, since for accounting reasons a service's slot
344 usage is carried over between users of the same port number.
345 */
346 typedef struct vchiq_service_quota_struct {
347 unsigned short slot_quota;
348 unsigned short slot_use_count;
349 unsigned short message_quota;
350 unsigned short message_use_count;
351 struct semaphore quota_event;
352 int previous_tx_index;
353 } VCHIQ_SERVICE_QUOTA_T;
354
355 typedef struct vchiq_shared_state_struct {
356
357 /* A non-zero value here indicates that the content is valid. */
358 int initialised;
359
360 /* The first and last (inclusive) slots allocated to the owner. */
361 int slot_first;
362 int slot_last;
363
364 /* The slot allocated to synchronous messages from the owner. */
365 int slot_sync;
366
367 /* Signalling this event indicates that owner's slot handler thread
368 ** should run. */
369 REMOTE_EVENT_T trigger;
370
371 /* Indicates the byte position within the stream where the next message
372 ** will be written. The least significant bits are an index into the
373 ** slot. The next bits are the index of the slot in slot_queue. */
374 int tx_pos;
375
376 /* This event should be signalled when a slot is recycled. */
377 REMOTE_EVENT_T recycle;
378
379 /* The slot_queue index where the next recycled slot will be written. */
380 int slot_queue_recycle;
381
382 /* This event should be signalled when a synchronous message is sent. */
383 REMOTE_EVENT_T sync_trigger;
384
385 /* This event should be signalled when a synchronous message has been
386 ** released. */
387 REMOTE_EVENT_T sync_release;
388
389 /* A circular buffer of slot indexes. */
390 int slot_queue[VCHIQ_MAX_SLOTS_PER_SIDE];
391
392 /* Debugging state */
393 int debug[DEBUG_MAX];
394 } VCHIQ_SHARED_STATE_T;
395
396 typedef struct vchiq_slot_zero_struct {
397 int magic;
398 short version;
399 short version_min;
400 int slot_zero_size;
401 int slot_size;
402 int max_slots;
403 int max_slots_per_side;
404 int platform_data[2];
405 VCHIQ_SHARED_STATE_T master;
406 VCHIQ_SHARED_STATE_T slave;
407 VCHIQ_SLOT_INFO_T slots[VCHIQ_MAX_SLOTS];
408 } VCHIQ_SLOT_ZERO_T;
409
410 struct vchiq_state_struct {
411 int id;
412 int initialised;
413 VCHIQ_CONNSTATE_T conn_state;
414 int is_master;
415 short version_common;
416
417 VCHIQ_SHARED_STATE_T *local;
418 VCHIQ_SHARED_STATE_T *remote;
419 VCHIQ_SLOT_T *slot_data;
420
421 unsigned short default_slot_quota;
422 unsigned short default_message_quota;
423
424 /* Event indicating connect message received */
425 struct semaphore connect;
426
427 /* Mutex protecting services */
428 struct mutex mutex;
429 VCHIQ_INSTANCE_T *instance;
430
431 /* Processes incoming messages */
432 VCHIQ_THREAD_T slot_handler_thread;
433
434 /* Processes recycled slots */
435 VCHIQ_THREAD_T recycle_thread;
436
437 /* Processes synchronous messages */
438 VCHIQ_THREAD_T sync_thread;
439
440 /* Local implementation of the trigger remote event */
441 struct semaphore trigger_event;
442
443 /* Local implementation of the recycle remote event */
444 struct semaphore recycle_event;
445
446 /* Local implementation of the sync trigger remote event */
447 struct semaphore sync_trigger_event;
448
449 /* Local implementation of the sync release remote event */
450 struct semaphore sync_release_event;
451
452 char *tx_data;
453 char *rx_data;
454 VCHIQ_SLOT_INFO_T *rx_info;
455
456 struct mutex slot_mutex;
457
458 struct mutex recycle_mutex;
459
460 struct mutex sync_mutex;
461
462 struct mutex bulk_transfer_mutex;
463
464 /* Indicates the byte position within the stream from where the next
465 ** message will be read. The least significant bits are an index into
466 ** the slot.The next bits are the index of the slot in
467 ** remote->slot_queue. */
468 int rx_pos;
469
470 /* A cached copy of local->tx_pos. Only write to local->tx_pos, and read
471 from remote->tx_pos. */
472 int local_tx_pos;
473
474 /* The slot_queue index of the slot to become available next. */
475 int slot_queue_available;
476
477 /* A flag to indicate if any poll has been requested */
478 int poll_needed;
479
480 /* Ths index of the previous slot used for data messages. */
481 int previous_data_index;
482
483 /* The number of slots occupied by data messages. */
484 unsigned short data_use_count;
485
486 /* The maximum number of slots to be occupied by data messages. */
487 unsigned short data_quota;
488
489 /* An array of bit sets indicating which services must be polled. */
490 atomic_t poll_services[VCHI_BITSET_SIZE(VCHIQ_MAX_SERVICES)];
491
492 /* The number of the first unused service */
493 int unused_service;
494
495 /* Signalled when a free slot becomes available. */
496 struct semaphore slot_available_event;
497
498 struct semaphore slot_remove_event;
499
500 /* Signalled when a free data slot becomes available. */
501 struct semaphore data_quota_event;
502
503 /* Incremented when there are bulk transfers which cannot be processed
504 * whilst paused and must be processed on resume */
505 int deferred_bulks;
506
507 struct state_stats_struct {
508 int slot_stalls;
509 int data_stalls;
510 int ctrl_tx_count;
511 int ctrl_rx_count;
512 int error_count;
513 } stats;
514
515 VCHIQ_SERVICE_T * services[VCHIQ_MAX_SERVICES];
516 VCHIQ_SERVICE_QUOTA_T service_quotas[VCHIQ_MAX_SERVICES];
517 VCHIQ_SLOT_INFO_T slot_info[VCHIQ_MAX_SLOTS];
518
519 VCHIQ_PLATFORM_STATE_T platform_state;
520 };
521
522 struct bulk_waiter {
523 VCHIQ_BULK_T *bulk;
524 struct semaphore event;
525 int actual;
526 };
527
528 extern spinlock_t bulk_waiter_spinlock;
529
530 extern int vchiq_core_log_level;
531 extern int vchiq_core_msg_log_level;
532 extern int vchiq_sync_log_level;
533
534 extern VCHIQ_STATE_T *vchiq_states[VCHIQ_MAX_STATES];
535
536 extern const char *
537 get_conn_state_name(VCHIQ_CONNSTATE_T conn_state);
538
539 extern VCHIQ_SLOT_ZERO_T *
540 vchiq_init_slots(void *mem_base, int mem_size);
541
542 extern VCHIQ_STATUS_T
543 vchiq_init_state(VCHIQ_STATE_T *state, VCHIQ_SLOT_ZERO_T *slot_zero,
544 int is_master);
545
546 extern VCHIQ_STATUS_T
547 vchiq_connect_internal(VCHIQ_STATE_T *state, VCHIQ_INSTANCE_T instance);
548
549 extern VCHIQ_SERVICE_T *
550 vchiq_add_service_internal(VCHIQ_STATE_T *state,
551 const VCHIQ_SERVICE_PARAMS_T *params, int srvstate,
552 VCHIQ_INSTANCE_T instance, VCHIQ_USERDATA_TERM_T userdata_term);
553
554 extern VCHIQ_STATUS_T
555 vchiq_open_service_internal(VCHIQ_SERVICE_T *service, int client_id);
556
557 extern VCHIQ_STATUS_T
558 vchiq_close_service_internal(VCHIQ_SERVICE_T *service, int close_recvd);
559
560 extern void
561 vchiq_terminate_service_internal(VCHIQ_SERVICE_T *service);
562
563 extern void
564 vchiq_free_service_internal(VCHIQ_SERVICE_T *service);
565
566 extern VCHIQ_STATUS_T
567 vchiq_shutdown_internal(VCHIQ_STATE_T *state, VCHIQ_INSTANCE_T instance);
568
569 extern VCHIQ_STATUS_T
570 vchiq_pause_internal(VCHIQ_STATE_T *state);
571
572 extern VCHIQ_STATUS_T
573 vchiq_resume_internal(VCHIQ_STATE_T *state);
574
575 extern void
576 remote_event_pollall(VCHIQ_STATE_T *state);
577
578 extern VCHIQ_STATUS_T
579 vchiq_bulk_transfer(VCHIQ_SERVICE_HANDLE_T handle,
580 VCHI_MEM_HANDLE_T memhandle, void *offset, int size, void *userdata,
581 VCHIQ_BULK_MODE_T mode, VCHIQ_BULK_DIR_T dir);
582
583 extern void
584 vchiq_dump_state(void *dump_context, VCHIQ_STATE_T *state);
585
586 extern void
587 vchiq_dump_service_state(void *dump_context, VCHIQ_SERVICE_T *service);
588
589 extern void
590 vchiq_loud_error_header(void);
591
592 extern void
593 vchiq_loud_error_footer(void);
594
595 extern void
596 request_poll(VCHIQ_STATE_T *state, VCHIQ_SERVICE_T *service, int poll_type);
597
598 static inline VCHIQ_SERVICE_T *
handle_to_service(VCHIQ_SERVICE_HANDLE_T handle)599 handle_to_service(VCHIQ_SERVICE_HANDLE_T handle)
600 {
601 VCHIQ_STATE_T *state = vchiq_states[(handle / VCHIQ_MAX_SERVICES) &
602 (VCHIQ_MAX_STATES - 1)];
603 if (!state)
604 return NULL;
605
606 return state->services[handle & (VCHIQ_MAX_SERVICES - 1)];
607 }
608
609 extern VCHIQ_SERVICE_T *
610 find_service_by_handle(VCHIQ_SERVICE_HANDLE_T handle);
611
612 extern VCHIQ_SERVICE_T *
613 find_service_by_port(VCHIQ_STATE_T *state, int localport);
614
615 extern VCHIQ_SERVICE_T *
616 find_service_for_instance(VCHIQ_INSTANCE_T instance,
617 VCHIQ_SERVICE_HANDLE_T handle);
618
619 extern VCHIQ_SERVICE_T *
620 find_closed_service_for_instance(VCHIQ_INSTANCE_T instance,
621 VCHIQ_SERVICE_HANDLE_T handle);
622
623 extern VCHIQ_SERVICE_T *
624 next_service_by_instance(VCHIQ_STATE_T *state, VCHIQ_INSTANCE_T instance,
625 int *pidx);
626
627 extern void
628 lock_service(VCHIQ_SERVICE_T *service);
629
630 extern void
631 unlock_service(VCHIQ_SERVICE_T *service);
632
633 /* The following functions are called from vchiq_core, and external
634 ** implementations must be provided. */
635
636 extern VCHIQ_STATUS_T
637 vchiq_prepare_bulk_data(VCHIQ_BULK_T *bulk,
638 VCHI_MEM_HANDLE_T memhandle, void *offset, int size, int dir);
639
640 extern void
641 vchiq_transfer_bulk(VCHIQ_BULK_T *bulk);
642
643 extern void
644 vchiq_complete_bulk(VCHIQ_BULK_T *bulk);
645
646 extern VCHIQ_STATUS_T
647 vchiq_copy_from_user(void *dst, const void *src, int size);
648
649 extern void
650 remote_event_signal(REMOTE_EVENT_T *event);
651
652 void
653 vchiq_platform_check_suspend(VCHIQ_STATE_T *state);
654
655 extern void
656 vchiq_platform_paused(VCHIQ_STATE_T *state);
657
658 extern VCHIQ_STATUS_T
659 vchiq_platform_resume(VCHIQ_STATE_T *state);
660
661 extern void
662 vchiq_platform_resumed(VCHIQ_STATE_T *state);
663
664 extern void
665 vchiq_dump(void *dump_context, const char *str, int len);
666
667 extern void
668 vchiq_dump_platform_state(void *dump_context);
669
670 extern void
671 vchiq_dump_platform_instances(void *dump_context);
672
673 extern void
674 vchiq_dump_platform_service_state(void *dump_context,
675 VCHIQ_SERVICE_T *service);
676
677 extern VCHIQ_STATUS_T
678 vchiq_use_service_internal(VCHIQ_SERVICE_T *service);
679
680 extern VCHIQ_STATUS_T
681 vchiq_release_service_internal(VCHIQ_SERVICE_T *service);
682
683 extern void
684 vchiq_on_remote_use(VCHIQ_STATE_T *state);
685
686 extern void
687 vchiq_on_remote_release(VCHIQ_STATE_T *state);
688
689 extern VCHIQ_STATUS_T
690 vchiq_platform_init_state(VCHIQ_STATE_T *state);
691
692 extern VCHIQ_STATUS_T
693 vchiq_check_service(VCHIQ_SERVICE_T *service);
694
695 extern void
696 vchiq_on_remote_use_active(VCHIQ_STATE_T *state);
697
698 extern VCHIQ_STATUS_T
699 vchiq_send_remote_use(VCHIQ_STATE_T *state);
700
701 extern VCHIQ_STATUS_T
702 vchiq_send_remote_release(VCHIQ_STATE_T *state);
703
704 extern VCHIQ_STATUS_T
705 vchiq_send_remote_use_active(VCHIQ_STATE_T *state);
706
707 extern void
708 vchiq_platform_conn_state_changed(VCHIQ_STATE_T *state,
709 VCHIQ_CONNSTATE_T oldstate, VCHIQ_CONNSTATE_T newstate);
710
711 extern void
712 vchiq_platform_handle_timeout(VCHIQ_STATE_T *state);
713
714 extern void
715 vchiq_set_conn_state(VCHIQ_STATE_T *state, VCHIQ_CONNSTATE_T newstate);
716
717
718 extern void
719 vchiq_log_dump_mem(const char *label, uint32_t addr, const void *voidMem,
720 size_t numBytes);
721
722 extern void
723 vchiq_core_initialize(void);
724
725 #endif
726