1/**
2 * \file
3 * \brief Bidirectional IPI signaling channel
4 */
5
6/*
7 * Copyright (c) 2009, 2010, 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, Universitaetstrasse 6, CH-8092 Zurich. Attn: Systems Group.
13 */
14
15#ifndef BARRELFISH_IPI_NOTIFY_H
16#define BARRELFISH_IPI_NOTIFY_H
17
18#include <barrelfish/waitset.h>
19#include <barrelfish/capabilities.h>
20#include <barrelfish/lmp_endpoints.h>
21
22struct ipi_notify;
23
24struct ipi_alloc_continuation {
25    /**
26     * \brief Handler which runs when a binding succeeds or fails
27     * \param st State pointer set in closure
28     * \param err Success/failure of binding
29     * \param uc On success, contains pointer to channel
30     */
31    void (*handler)(void *st, errval_t err, struct ipi_notify *rc);
32    void *st;
33};
34
35/// A bidirectional IPI channel
36struct ipi_notify {
37    struct capref my_notify_cap, rmt_notify_cap, ep;
38    struct lmp_endpoint *iep;
39    struct ipi_alloc_continuation cont;
40    struct event_closure closure;
41};
42
43errval_t ipi_notify_init(struct ipi_notify *rn, struct capref rmt_notify_cap,
44                         struct capref my_notify_cap, struct capref ep,
45                         struct lmp_endpoint *iep);
46errval_t ipi_notify_alloc(struct ipi_notify *uc,
47                          struct ipi_alloc_continuation cont);
48errval_t ipi_notify_set(struct ipi_notify *uc, struct capref notify);
49void ipi_notify_destroy(struct ipi_notify *uc);
50void ipi_init(void);
51errval_t ipi_notify_register(struct ipi_notify *uc,
52                             struct waitset *ws,
53                             struct event_closure closure);
54
55/**
56 * \brief Cancel an event registration made with ipi_chan_register_recv()
57 *
58 * \param uc IPI channel
59 */
60static inline errval_t ipi_notify_deregister(struct ipi_notify *uc)
61{
62    return lmp_endpoint_deregister(uc->iep);
63}
64
65static inline errval_t ipi_notify_raise(struct ipi_notify *rc)
66{
67    // Send notification
68    return invoke_ipi_notify_send(rc->rmt_notify_cap);
69}
70
71#endif // BARRELFISH_IPI_NOTIFY_H
72