3 * \brief Memobj definitions
7 * Copyright (c) 2009, 2010, 2011, ETH Zurich.
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.
15 #ifndef LIBBARRELFISH_MEMOBJ_H
16 #define LIBBARRELFISH_MEMOBJ_H
18 #include <barrelfish/slab.h>
19 #include <sys/cdefs.h>
23 // FIXME: these enum names need to be scoped (e.g. MEMOBJ_X rather than X) -AB
30 MEMOBJ_VFS, // see lib/vfs/mmap.c
35 typedef uint32_t memobj_flags_t;
36 typedef uint32_t vs_prot_flags_t;
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,
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);
62 struct vregion *region;
63 struct vregion_list *next;
66 /// Public interface for 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
74 struct memobj_pinned {
75 struct memobj m; ///< Public interface
76 struct vregion *vregion; ///< Pointer to the single vregion
79 struct 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
86 struct memobj_one_frame {
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
93 struct memobj_one_frame_lazy {
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
100 struct 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;
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`
119 * this memobj can be mapped into a single vregion and backed by a fixed number
120 * of equal sized frames
122 struct memobj_fixed {
123 struct memobj m; ///< public memobj interface
124 size_t count; ///< the number of frames
125 size_t chunk_size; ///< the size of the frames
126 struct vregion *vregion; ///< the associated vregion
127 struct capref *frames; ///< the tracked frames
128 size_t *offsets; ///< the offset into the tracked frames
132 * this memobj can be mapped into a single vregion and is backed by a s
133 * this memobj can be mapped into a single vregion and backed by a fixed number
134 * of equal sized frames
137 struct memobj m; ///< public memobj interface
138 uint32_t node_count; ///< number of nodes in the machine
139 size_t stride; ///< size of the regions to map
140 struct vregion *vregion; ///< the associated vregion
141 struct capref *frames; ///< the tracked frames
144 errval_t memobj_create_pinned(struct memobj_pinned *memobj, size_t size,
145 memobj_flags_t flags);
147 errval_t memobj_create_anon(struct memobj_anon *memobj, size_t size,
148 memobj_flags_t flags);
149 errval_t memobj_destroy_anon(struct memobj *memobj, bool delete_caps);
151 errval_t memobj_create_one_frame(struct memobj_one_frame *memobj, size_t size,
152 memobj_flags_t flags);
153 errval_t memobj_destroy_one_frame(struct memobj *memobj);
155 errval_t memobj_create_one_frame_lazy(struct memobj_one_frame_lazy *memobj,
156 size_t size, memobj_flags_t flags,
157 struct capref frame, size_t chunk_size);
158 errval_t memobj_create_one_frame_one_map(struct memobj_one_frame_one_map *memobj,
159 size_t size, memobj_flags_t flags);
162 errval_t memobj_create_fixed(struct memobj_fixed *memobj, size_t size,
163 memobj_flags_t flags, size_t count,
166 errval_t memobj_destroy_fixed(struct memobj *memobj);
168 errval_t memobj_create_numa(struct memobj_numa *numa, size_t size,
169 memobj_flags_t flags, size_t node_count, size_t stride);
171 errval_t memobj_destroy_numa(struct memobj *memobj);
175 #endif // LIBBARRELFISH_MEMOBJ_H