1/** 2 * \file 3 * \brief Memobj definitions 4 */ 5 6/* 7 * Copyright (c) 2009, 2010, 2011, 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#ifndef LIBBARRELFISH_MEMOBJ_H 16#define LIBBARRELFISH_MEMOBJ_H 17 18#include <barrelfish/slab.h> 19#include <sys/cdefs.h> 20 21__BEGIN_DECLS 22 23// FIXME: these enum names need to be scoped (e.g. MEMOBJ_X rather than X) -AB 24enum memobj_type { 25 ANONYMOUS, 26 ONE_FRAME, 27 ONE_FRAME_LAZY, 28 PINNED, 29 ONE_FRAME_ONE_MAP, 30 MEMOBJ_VFS, // see lib/vfs/mmap.c 31 MEMOBJ_FIXED, 32 MEMOBJ_NUMA 33}; 34 35typedef uint32_t memobj_flags_t; 36typedef uint32_t vs_prot_flags_t; 37 38struct memobj; 39struct vregion; 40struct memobj_funcs { 41 errval_t (*map_region)(struct memobj *memobj, struct vregion *vregion); 42 errval_t (*unmap_region)(struct memobj* memobj, struct vregion* region); 43 errval_t (*protect)(struct memobj* memobj, struct vregion* region, 44 genvaddr_t offset, size_t range, vs_prot_flags_t flags); 45 errval_t (*pin)(struct memobj* memobj, struct vregion* region, 46 genvaddr_t offset, size_t range); 47 errval_t (*unpin)(struct memobj* memobj, struct vregion* region, 48 genvaddr_t offset, size_t range); 49 errval_t (*fill)(struct memobj *memobj, genvaddr_t offset, struct capref frame, 50 size_t size); 51 errval_t (*fill_foff)(struct memobj *memobj, genvaddr_t offset, struct capref frame, 52 size_t size, genpaddr_t foffset); 53 errval_t (*unfill)(struct memobj *memobj, genvaddr_t offset, 54 struct capref *ret_frame, genvaddr_t *ret_offset); 55 errval_t (*pagefault)(struct memobj* memobj, struct vregion* region, 56 genvaddr_t offset, vm_fault_type_t type); 57 errval_t (*pager_free)(struct memobj* memobj, size_t size, 58 struct capref *frames, size_t num_frames); 59}; 60 61struct vregion_list { 62 struct vregion *region; 63 struct vregion_list *next; 64}; 65 66/// Public interface for memobj 67struct memobj { 68 size_t size; ///< Size of the object 69 memobj_flags_t flags; ///< Flags for the object. NYI. 70 enum memobj_type type; ///< Type of the memory object 71 struct memobj_funcs f; ///< Function pointers 72}; 73 74struct memobj_pinned { 75 struct memobj m; ///< Public interface 76 struct vregion *vregion; ///< Pointer to the single vregion 77}; 78 79struct memobj_one_frame_one_map { 80 struct memobj m; ///< Public interface 81 struct vregion *vregion; ///< Pointer to the single vregion 82 struct capref frame; ///< Frame tracked by the obj 83 genpaddr_t offset; ///< Offset into the frame 84}; 85 86struct memobj_one_frame { 87 struct memobj m; 88 struct vregion_list *vregion_list; ///< List of vregions mapped into the obj 89 struct capref frame; ///< Frame tracked by the obj 90 genpaddr_t offset; ///< Offset into the frame 91}; 92 93struct memobj_one_frame_lazy { 94 struct memobj m; 95 struct vregion_list *vregion_list; ///< List of vregions mapped into the obj 96 struct capref frame; ///< Frame tracked by the obj 97 size_t chunk_size; ///< Amount to map in per pagefault 98}; 99 100struct memobj_frame_list { 101 genpaddr_t offset; ///< Offset into the frame 102 struct capref frame; ///< Capability of the frame 103 size_t size; ///< Size of the frame 104 genpaddr_t pa; ///< XXX: physical address of frame 105 genpaddr_t foffset; ///< Offset into frame 106 struct memobj_frame_list *next; 107}; 108 109struct memobj_anon { 110 struct memobj m; 111 struct vregion_list *vregion_list; ///< List of vregions mapped into the obj 112 struct slab_allocator vregion_slab; ///< Slab to back the vregion list 113 struct memobj_frame_list *frame_list; ///< List of frames tracked by the obj 114 struct slab_allocator frame_slab; ///< Slab to back the frame list 115 bool frame_slab_refilling; ///< True, iff we're currently refilling `frame_slab` 116 bool vregion_slab_refilling; ///< True, iff we're currently refilling `vregion_slab` 117}; 118 119/** 120 * this memobj can be mapped into a single vregion and backed by a fixed number 121 * of equal sized frames 122 */ 123struct memobj_fixed { 124 struct memobj m; ///< public memobj interface 125 size_t count; ///< the number of frames 126 size_t chunk_size; ///< the size of the frames 127 struct vregion *vregion; ///< the associated vregion 128 struct capref *frames; ///< the tracked frames 129 size_t *offsets; ///< the offset into the tracked frames 130}; 131 132/** 133 * this memobj can be mapped into a single vregion and is backed by a s 134 * this memobj can be mapped into a single vregion and backed by a fixed number 135 * of equal sized frames 136 */ 137struct memobj_numa { 138 struct memobj m; ///< public memobj interface 139 uint32_t node_count; ///< number of nodes in the machine 140 size_t stride; ///< size of the regions to map 141 struct vregion *vregion; ///< the associated vregion 142 struct capref *frames; ///< the tracked frames 143}; 144 145errval_t memobj_create_pinned(struct memobj_pinned *memobj, size_t size, 146 memobj_flags_t flags); 147 148errval_t memobj_create_anon(struct memobj_anon *memobj, size_t size, 149 memobj_flags_t flags); 150errval_t memobj_destroy_anon(struct memobj *memobj, bool delete_caps); 151 152errval_t memobj_create_one_frame(struct memobj_one_frame *memobj, size_t size, 153 memobj_flags_t flags); 154errval_t memobj_destroy_one_frame(struct memobj *memobj); 155 156errval_t memobj_create_one_frame_lazy(struct memobj_one_frame_lazy *memobj, 157 size_t size, memobj_flags_t flags, 158 struct capref frame, size_t chunk_size); 159errval_t memobj_create_one_frame_one_map(struct memobj_one_frame_one_map *memobj, 160 size_t size, memobj_flags_t flags); 161 162 163errval_t memobj_create_fixed(struct memobj_fixed *memobj, size_t size, 164 memobj_flags_t flags, size_t count, 165 size_t chunk_size); 166 167errval_t memobj_destroy_fixed(struct memobj *memobj); 168 169errval_t memobj_create_numa(struct memobj_numa *numa, size_t size, 170 memobj_flags_t flags, size_t node_count, size_t stride); 171 172errval_t memobj_destroy_numa(struct memobj *memobj); 173 174__END_DECLS 175 176#endif // LIBBARRELFISH_MEMOBJ_H 177