1/**
2 * \file
3 * \brief IPI notification mechanism
4 */
5
6/*
7 * Copyright (c) 2007, 2008, 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, Haldeneggsteig 4, CH-8092 Zurich. Attn: Systems Group.
13 */
14
15#include "monitor.h"
16#include <notify_ipi.h>
17
18static int glbl_chanid = 1;
19
20errval_t notification_set(int chanid, struct capref ep)
21{
22    return invoke_monitor_ipi_register(ep, chanid);
23}
24
25errval_t notification_allocate(struct capref ep, int *chanid)
26{
27    *chanid = glbl_chanid;
28    glbl_chanid++;
29
30    if(get_cap_addr(ep) != CPTR_NULL) {
31        return notification_set(*chanid, ep);
32    } else {
33        return SYS_ERR_OK;
34    }
35}
36
37errval_t notification_create_cap(int chanid, coreid_t coreid,
38                                 struct capref *retcap)
39{
40    errval_t err;
41
42    /* printf("%d: creating notify cap with chanid %d, coreid %d, caller %p\n", */
43    /*        my_core_id, chanid, coreid, __builtin_return_address(0)); */
44
45    /* Construct the notification capability */
46    struct capability notify_cap = {
47        .type = ObjType_Notify_IPI,
48        .rights = CAPRIGHTS_READ_WRITE, // XXX
49        .u.notify_ipi = {
50            .coreid = coreid,
51            .chanid = chanid
52        }
53    };
54
55    err = slot_alloc(retcap);
56    if (err_is_fail(err)) {
57        DEBUG_ERR(err, "Failed to allocate slot from channel_alloc");
58        printf("Failed to allocate slot from channel_alloc\n");
59        abort(); //XXX
60    }
61    err = monitor_cap_create(*retcap, &notify_cap, 0);
62    if (err_is_fail(err)) {
63        DEBUG_ERR(err, "monitor_cap_create failed");
64        printf("monitor_cap_create failed\n");
65        abort(); //XXX
66    }
67
68    return SYS_ERR_OK;
69}
70