1/*
2 * Copyright (c) 2018, ETH Zurich.
3 * All rights reserved.
4 *
5 * This file is distributed under the terms in the attached LICENSE file.
6 * If you do not find this file, copies can be found by writing to:
7 * ETH Zurich D-INFK, Universitaetstrasse 6, CH-8092 Zurich. Attn: Systems Group.
8 */
9
10#ifndef LIBBARRELFISH_PMAP_PRIV_H
11#define LIBBARRELFISH_PMAP_PRIV_H
12
13/**
14 * \brief internal mapping function. This assumes that enough slabs are
15 * available for metadata.
16 */
17errval_t do_map(struct pmap *pmap, genvaddr_t vaddr,
18                struct capref frame, size_t offset, size_t size,
19                vregion_flags_t flags, size_t *retoff, size_t *retsize);
20
21/**
22 * \brief return the number of slabs required for mapping a region of size
23 * `bytes` with small pages.
24 */
25size_t max_slabs_required(size_t bytes);
26
27errval_t pmap_slab_refill(struct pmap *pmap, struct slab_allocator *slab,
28                          size_t max_slabs_for_mapping);
29
30errval_t pmap_vnode_mgmt_current_init(struct pmap *pmap);
31
32static inline void
33set_mapping_cap(struct pmap *pmap, struct vnode *vnode,
34                struct vnode *root, uint16_t entry)
35{
36    assert(root->v.is_vnode);
37    assert(entry < PTABLE_ENTRIES);
38#ifdef GLOBAL_MCN
39    vnode->v.mapping.cnode = root->u.vnode.mcnode[entry / L2_CNODE_SLOTS];
40    vnode->v.mapping.slot  = entry % L2_CNODE_SLOTS;
41    assert(!cnoderef_is_null(vnode->v.mapping.cnode));
42    assert(!capref_is_null(vnode->v.mapping));
43#else
44    /* just use the slot allocator associated with the pmap. */
45    errval_t err;
46    err = pmap->slot_alloc->alloc(pmap->slot_alloc, &vnode->v.mapping);
47    // TODO: error propagation
48    assert(err_is_ok(err));
49#endif
50}
51
52#endif // LIBBARRELFISH_PMAP_PRIV_H
53