2 * This file is part of DDEKit.
4 * (c) 2006-2012 Bjoern Doebel <doebel@os.inf.tu-dresden.de>
5 * Christian Helmuth <ch12@os.inf.tu-dresden.de>
6 * Thomas Friebel <tf13@os.inf.tu-dresden.de>
7 * economic rights: Technische Universitaet Dresden (Germany)
9 * This file is part of TUD:OS and distributed under the terms of the
10 * GNU General Public License 2.
11 * Please see the COPYING-GPL-2 file for details.
15 * \brief Memory subsystem
20 #include <l4/sys/compiler.h>
31 * Store user pointer in slab cache
33 * \param slab pointer to slab cache
34 * \param data user pointer
36 void ddekit_slab_set_data(struct ddekit_slab * slab, void *data);
39 * Read user pointer from slab cache
41 * \param slab pointer to slab cache
43 * \return stored user pointer or 0
45 void *ddekit_slab_get_data(struct ddekit_slab * slab);
48 * Allocate slab in slab cache
50 * \param slab pointer to slab cache
52 * \return pointer to allocated slab
54 void *ddekit_slab_alloc(struct ddekit_slab * slab);
57 * Deallocate slab in slab cache
59 * \param slab pointer to slab cache
60 * \param objp pointer to allocated slab
62 void ddekit_slab_free(struct ddekit_slab * slab, void *objp);
65 * Setup page cache for all slabs
67 * \param pages maximal number of memory pages
69 * If 'pages' is too low, memory pages may be given back to the memory server
70 * (dm_phys) and just to be allocated again later. This hits performance (but
71 * saves memory). Increase 'pages' to avoid this thrashing-like effect.
73 * If the maximal number of unused pages is exceeded, subsequent deallocation
74 * will be freed at the memory server. This page cache caches pages from all
77 void ddekit_slab_setup_page_cache(unsigned pages);
82 * \param slab pointer to slab cache structure
84 void ddekit_slab_destroy(struct ddekit_slab * slab);
87 * Initialize slab cache
89 * \param size size of cache objects
90 * \param contiguous make this slab use physically contiguous memory
92 * \return pointer to new slab cache or 0 on error
94 struct ddekit_slab * ddekit_slab_init(unsigned size, int contiguous);
97 /**********************
98 ** Memory allocator **
99 **********************/
102 * Allocate large memory block
104 * \param size block size
105 * \return pointer to new memory block
107 * Allocations via this allocator may be slow (because memory servers are
108 * involved) and should be used only for large (i.e., > page size) blocks. If
109 * allocations/deallocations are relatively dynamic this may not be what you
112 * Allocated blocks have valid virt->phys mappings and are physically
115 void *ddekit_large_malloc(int size);
118 * Free large memory block
120 * \param p pointer to memory block
122 void ddekit_large_free(void *p);
125 * contig_malloc() is the lowest-level allocator interface one could implement.
126 * we should consider to provide vmalloc() too. */
127 void *ddekit_contig_malloc(
129 unsigned long low, unsigned long high,
130 unsigned long alignment, unsigned long boundary
134 /*****************************
135 ** Simple memory allocator **
136 *****************************/
139 * Allocate memory block via simple allocator
141 * \param size block size
142 * \return pointer to new memory block
144 * The blocks allocated via this allocator CANNOT be used for DMA or other
145 * device operations, i.e., there exists no virt->phys mapping.
147 void *ddekit_simple_malloc(unsigned size);
150 * Free memory block via simple allocator
152 * \param p pointer to memory block
154 void ddekit_simple_free(void *p);