1/** 2 * \file 3 * \brief UMP endpoint declarations 4 */ 5 6/* 7 * Copyright (c) 2009, 2010, 2011, ETH Zurich. 8 * All rights reserved. 9 * 10 * This file is distributed under the terms in the attached LICENSE file. 11 * If you do not find this file, copies can be found by writing to: 12 * ETH Zurich D-INFK, Haldeneggsteig 4, CH-8092 Zurich. Attn: Systems Group. 13 */ 14 15#ifndef LIBBARRELFISH_UMP_ENDPOINT_H 16#define LIBBARRELFISH_UMP_ENDPOINT_H 17 18#include <sys/cdefs.h> 19 20#include <barrelfish/waitset.h> 21#include <barrelfish/ump_impl.h> 22 23__BEGIN_DECLS 24 25/// Incoming UMP endpoint 26struct ump_endpoint { 27 struct waitset_chanstate waitset_state; ///< Waitset per-channel state 28 struct ump_chan_state chan; ///< Incoming UMP channel state to poll 29}; 30 31errval_t ump_endpoint_init(struct ump_endpoint *ep, volatile void *buf, 32 size_t bufsize); 33void ump_endpoint_destroy(struct ump_endpoint *ep); 34errval_t ump_endpoint_register(struct ump_endpoint *ep, struct waitset *ws, 35 struct event_closure closure); 36errval_t ump_endpoint_deregister(struct ump_endpoint *ep); 37void ump_endpoint_migrate(struct ump_endpoint *ep, struct waitset *ws); 38 39/** 40 * \brief Returns true if there is a message pending on the given UMP endpoint 41 */ 42static inline bool ump_endpoint_can_recv(struct ump_endpoint *ep) 43{ 44 return ump_impl_poll(&ep->chan) != NULL; 45} 46 47/** 48 * \brief Retrieve a message from the given UMP endpoint, if possible 49 * 50 * Non-blocking, may fail if there are no messages available. 51 * 52 * \param ep UMP endpoint 53 * \param retmsg Storage for incoming message 54 */ 55static inline errval_t ump_endpoint_recv(struct ump_endpoint *ep, 56 volatile struct ump_message **msg) 57{ 58 *msg = ump_impl_recv(&ep->chan); 59 60 if(*msg != NULL) { 61 return SYS_ERR_OK; 62 } else { 63 return LIB_ERR_NO_UMP_MSG; 64 } 65} 66 67/** 68 * \brief Return true if there's a message available 69 * 70 * \param channel UMP channal 71 */ 72static inline bool ump_endpoint_poll(struct waitset_chanstate *channel) 73{ 74 struct ump_endpoint *ep = (struct ump_endpoint *) 75 ((char *)channel - offsetof(struct ump_endpoint, waitset_state)); 76 77 return ump_endpoint_can_recv(ep); 78} 79 80 81__END_DECLS 82 83#endif // LIBBARRELFISH_UMP_ENDPOINT_H 84