/* ---------------------------------------------------------------------- * check to see if there are any pending messages * * if there are no messages, return 0 * * otherwise, fetch and process the first queued message (which will * be either a command or response from host) * -------------------------------------------------------------------- */ static int vc_ilcs_process_message( int block ) { int32_t success; void *ptr; unsigned char *msg; uint32_t i, msg_len, cmd, xid; success = vchi_msg_peek( vc_ilcsg.vchi_handle, &ptr, &msg_len, block ? VCHI_FLAGS_BLOCK_UNTIL_OP_COMPLETE : VCHI_FLAGS_NONE); vc_assert(!block || !success); if ( success != 0 ) return 0; // no more messages msg = ptr; cmd = vchi_readbuf_uint32( msg ); xid = vchi_readbuf_uint32( msg + 4 ); if ( cmd == IL_RESPONSE ) { vc_ilcs_response( xid, msg + 8, msg_len - 8 ); vchi_msg_remove( vc_ilcsg.vchi_handle ); } else { // we can only handle commands if we have space to copy the message first if(vc_ilcsg.msg_inuse == VC_ILCS_MSG_INUSE_MASK) { // this shouldn't happen, since we have more msg slots than the // remote side is allowed concurrent clients. We don't cope // with this assumption not being true. vc_assert(0); return 0; } i = 0; while(vc_ilcsg.msg_inuse & (1<<i)) i++; vc_ilcsg.msg_inuse |= (1<<i); memcpy( vc_ilcsg.msg[i], msg + 8, msg_len - 8 ); vchi_msg_remove( vc_ilcsg.vchi_handle ); vc_ilcs_command( cmd, xid, vc_ilcsg.msg[i], msg_len - 8); // mark the message copy as free vc_ilcsg.msg_inuse &= ~(1<<i); } return 1; }
/* ---------------------------------------------------------------------- * check to see if there are any pending messages * * if there are no messages, return 0 * * otherwise, fetch and process the first queued message (which will * be either a command or response from host) * -------------------------------------------------------------------- */ static int vc_ilcs_process_message( void ) { int32_t success; void *ptr; unsigned char *msg; VCHI_HELD_MSG_T msg_handle; uint32_t msg_len; success = vchi_msg_hold( vc_ilcsg.vchi_handle, &ptr, &msg_len, VCHI_FLAGS_NONE, &msg_handle ); if ( success != 0 ) return 0; // no more messages msg = ptr; uint32_t cmd = vchi_readbuf_uint32( msg ); uint32_t xid = vchi_readbuf_uint32( msg + 4 ); log_add(cmd, msg + 8, msg_len - 8, "<-"); if ( cmd == IL_RESPONSE ) vc_ilcs_response( xid, msg + 8, msg_len - 8 ); else //vc_ilcs_command( cmd, xid, msg + 8, msg_len - 8 ); { msg += 8; msg_len -= 8; if(component_in_kernel(msg)) { vc_ilcs_command( cmd, xid, msg, msg_len); } else { vc_ilcs_command_usr( cmd, xid, msg, msg_len); } } success = vchi_held_msg_release( &msg_handle ); vc_assert(success == 0); return 1; }