1/*
2 * Copyright 2017, Data61
3 * Commonwealth Scientific and Industrial Research Organisation (CSIRO)
4 * ABN 41 687 119 230.
5 *
6 * This software may be distributed and modified according to the terms of
7 * the BSD 2-Clause license. Note that NO WARRANTY is provided.
8 * See "LICENSE_BSD2.txt" for details.
9 *
10 * @TAG(DATA61_BSD)
11 */
12
13#pragma once
14
15/* This file provides convenient wrappers around seL4 invocations (on CNodes and Untypeds)
16 * such that allocator operations are allocator independent.
17 *
18 * Use these and you will never have
19 * to look at the cspacepath_t definition again!
20 */
21#include <autoconf.h>
22#include <sel4vka/gen_config.h>
23#include <vka/cspacepath_t.h>
24#include <vka/object.h>
25
26#ifndef CONFIG_KERNEL_MCS
27static inline int vka_cnode_saveCaller(const cspacepath_t *src)
28{
29    return seL4_CNode_SaveCaller(
30               /* _service */      src->root,
31               /* index */         src->capPtr,
32               /* depth */         src->capDepth
33           );
34}
35#endif
36
37static inline int vka_cnode_copy(const cspacepath_t *dest, const cspacepath_t *src, seL4_CapRights_t rights)
38{
39    return seL4_CNode_Copy(
40               /* _service */      dest->root,
41               /* dest_index */    dest->capPtr,
42               /* destDepth */    dest->capDepth,
43               /* src_root */      src->root,
44               /* src_index */     src->capPtr,
45               /* src_depth */     src->capDepth,
46               /* rights */        rights
47           );
48}
49
50static inline int vka_cnode_delete(const cspacepath_t *src)
51{
52    return seL4_CNode_Delete(
53               /* _service */      src->root,
54               /* index */         src->capPtr,
55               /* depth */         src->capDepth
56           );
57}
58
59static inline int vka_cnode_mint(const cspacepath_t *dest, const cspacepath_t *src,
60                                 seL4_CapRights_t rights, seL4_Word badge)
61{
62    return seL4_CNode_Mint(
63               /* _service */      dest->root,
64               /* dest_index */    dest->capPtr,
65               /* destDepth */    dest->capDepth,
66               /* src_root */      src->root,
67               /* src_index */     src->capPtr,
68               /* src_depth */     src->capDepth,
69               /* rights */        rights,
70               /* badge  */        badge
71           );
72}
73
74static inline int vka_cnode_move(const cspacepath_t *dest, const cspacepath_t *src)
75{
76    return seL4_CNode_Move(
77               /* _service */      dest->root,
78               /* dest_index */    dest->capPtr,
79               /* destDepth */    dest->capDepth,
80               /* src_root */      src->root,
81               /* src_index */     src->capPtr,
82               /* src_depth */     src->capDepth
83           );
84}
85
86static inline int vka_cnode_mutate(const cspacepath_t *dest, const cspacepath_t *src,
87                                   seL4_Word badge)
88{
89    return seL4_CNode_Mutate(
90               /* _service */      dest->root,
91               /* dest_index */    dest->capPtr,
92               /* destDepth */    dest->capDepth,
93               /* src_root */      src->root,
94               /* src_index */     src->capPtr,
95               /* src_depth */     src->capDepth,
96               /* badge  */        badge
97           );
98}
99
100static inline int vka_cnode_cancelBadgedSends(const cspacepath_t *src)
101{
102    return seL4_CNode_CancelBadgedSends(
103               /* _service */      src->root,
104               /* index */         src->capPtr,
105               /* depth */         src->capDepth
106           );
107}
108
109static inline int vka_cnode_revoke(const cspacepath_t *src)
110{
111    return seL4_CNode_Revoke(
112               /* _service */      src->root,
113               /* index */         src->capPtr,
114               /* depth */         src->capDepth
115           );
116}
117
118static inline int vka_cnode_rotate(const cspacepath_t *dest, seL4_Word dest_badge, const cspacepath_t *pivot,
119                                   seL4_Word pivot_badge, const cspacepath_t *src)
120{
121    return seL4_CNode_Rotate(dest->root, dest->capPtr, dest->capDepth, dest_badge,
122                             pivot->root, pivot->capPtr, pivot->capDepth, pivot_badge,
123                             src->root, src->capPtr, src->capDepth);
124}
125
126//TODO: implement rotate
127
128/**
129 * Retype num_objects objects from untyped into type starting from destination slot dest.
130 *
131 * size_bits is only relevant for dynamically sized objects - untypeds + captables
132 */
133static inline int vka_untyped_retype(vka_object_t *untyped, int type, int size_bits, int num_objects,
134                                     const cspacepath_t *dest)
135{
136    size_bits = vka_get_object_size(type, size_bits);
137    return seL4_Untyped_Retype(untyped->cptr, type, size_bits, dest->root, dest->dest, dest->destDepth, dest->offset,
138                               num_objects);
139}
140
141