1/**
2 * \file
3 * \brief Capability invocations specific to the monitors
4 */
5
6/*
7 * Copyright (c) 2007, 2008, 2009, 2010, 2016, 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 MONITOR_INVOCATIONS_ARCH_H
16#define MONITOR_INVOCATIONS_ARCH_H
17
18#include <barrelfish/syscall_arch.h>
19#include <barrelfish/caddr.h>
20#include <barrelfish/invocations_arch.h>
21#include <barrelfish_kpi/cpu.h>
22#include <barrelfish_kpi/syscalls.h>
23#include "monitor_debug.h"
24
25static inline errval_t
26invoke_monitor_create_cap(uint64_t *raw, capaddr_t caddr, int level, capaddr_t slot, coreid_t owner)
27{
28    DEBUG_INVOCATION("%s: called from %p\n", __FUNCTION__, __builtin_return_address(0));
29    return cap_invoke6(cap_kernel, KernelCmd_Create_cap, caddr, level, slot,
30                       owner, (uintptr_t)raw).error;
31}
32
33STATIC_ASSERT(ObjType_Num < 0xFFFF, "retype invocation argument packing does not truncate enum objtype");
34static inline errval_t
35invoke_monitor_remote_cap_retype(capaddr_t src_root, capaddr_t src, gensize_t offset,
36                                 enum objtype newtype, gensize_t objsize, size_t count,
37                                 capaddr_t to_cspace, capaddr_t to, capaddr_t slot,
38                                 int level)
39{
40    DEBUG_INVOCATION("%s: called from %p\n", __FUNCTION__, __builtin_return_address(0));
41    assert(newtype < ObjType_Num);
42    assert(level <= 0xFF);
43    assert(slot <= 0xFFFF);
44    return cap_invoke10(cap_kernel, KernelCmd_Retype,
45                        src_root, src, offset, ((uint32_t)level << 16) | newtype,
46                        objsize, count, to_cspace, to, slot).error;
47}
48
49static inline errval_t
50invoke_monitor_revoke_mark_relations(uint64_t *raw_base)
51{
52    DEBUG_INVOCATION("%s: called from %p\n", __FUNCTION__, __builtin_return_address(0));
53    // XXX: this is assumed in client code of this function!
54    assert(sizeof(struct capability) / sizeof(uint64_t) <= 4);
55    return cap_invoke2(cap_kernel, KernelCmd_Revoke_mark_relations,
56                       (uintptr_t)raw_base).error;
57}
58
59static inline errval_t
60invoke_monitor_has_descendants(uint64_t *raw, bool *res)
61{
62    DEBUG_INVOCATION("%s: called from %p\n", __FUNCTION__, __builtin_return_address(0));
63    // XXX: this is assumed in client code of this function!
64    assert(sizeof(struct capability) / sizeof(uint64_t) <= 4);
65
66    struct sysret sysret;
67    sysret = cap_invoke2(cap_kernel, KernelCmd_Has_descendants,
68                         (uintptr_t)raw);
69    if (err_is_ok(sysret.error)) {
70        *res = sysret.value;
71    }
72    return sysret.error;
73}
74
75static inline errval_t
76invoke_monitor_is_retypeable(uint64_t *raw, gensize_t offset,
77                             gensize_t objsize, size_t count)
78{
79    DEBUG_INVOCATION("%s: called from %p\n", __FUNCTION__, __builtin_return_address(0));
80    assert(sizeof(struct capability) <= 4*sizeof(uint64_t));
81    return cap_invoke5(cap_kernel, KernelCmd_Is_retypeable,
82                       (uintptr_t)raw, offset, objsize, count).error;
83}
84
85/**
86 * \brief Set up tracing in the kernel
87 *
88 */
89static inline errval_t
90invoke_trace_setup(struct capref cap)
91{
92    DEBUG_INVOCATION("%s: called from %p\n", __FUNCTION__, __builtin_return_address(0));
93    USER_PANIC("NYI");
94    return LIB_ERR_NOT_IMPLEMENTED;
95}
96
97static inline errval_t
98invoke_domain_id(struct capref cap, uint64_t domain_id)
99{
100    DEBUG_INVOCATION("%s: called from %p\n", __FUNCTION__, __builtin_return_address(0));
101    USER_PANIC("NYI");
102    return LIB_ERR_NOT_IMPLEMENTED;
103}
104
105static inline errval_t invoke_monitor_sync_timer(uint64_t synctime)
106{
107    DEBUG_INVOCATION("%s: called from %p\n", __FUNCTION__, __builtin_return_address(0));
108    // XXX: could do cap_invoke1() here, as we have 64 bit GP registers
109    return cap_invoke2(cap_kernel, synctime >> 32, synctime & 0xffffffff).error;
110}
111
112static inline errval_t
113invoke_monitor_copy_existing(uint64_t *raw, capaddr_t croot_addr, capaddr_t cn_addr,
114                             int cn_level, cslot_t slot)
115{
116    DEBUG_INVOCATION("%s: called from %p\n", __FUNCTION__, __builtin_return_address(0));
117    // XXX: this is assumed in client code of this function!
118    assert(sizeof(struct capability) <= 4*sizeof(uint64_t));
119
120    return cap_invoke6(cap_kernel, KernelCmd_Copy_existing,
121                       croot_addr, cn_addr, cn_level, slot, (uintptr_t)raw).error;
122}
123
124#endif
125