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