]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/dde/include/ddekit/memory.h
update
[l4.git] / l4 / pkg / dde / include / ddekit / memory.h
1 /*
2  * This file is part of DDEKit.
3  *
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)
8  *
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.
12  */
13
14 /*
15  * \brief   Memory subsystem
16  */
17
18 #pragma once
19
20 #include <l4/sys/compiler.h>
21
22 EXTERN_C_BEGIN
23
24 /*******************
25  ** Slab facility **
26  *******************/
27
28 struct ddekit_slab;
29
30 /**
31  * Store user pointer in slab cache
32  *
33  * \param slab  pointer to slab cache
34  * \param data  user pointer
35  */
36 void ddekit_slab_set_data(struct ddekit_slab * slab, void *data);
37
38 /**
39  * Read user pointer from slab cache
40  *
41  * \param slab  pointer to slab cache
42  *
43  * \return stored user pointer or 0
44  */
45 void *ddekit_slab_get_data(struct ddekit_slab * slab);
46
47 /**
48  * Allocate slab in slab cache
49  *
50  * \param slab  pointer to slab cache
51  *
52  * \return pointer to allocated slab
53  */
54 void *ddekit_slab_alloc(struct ddekit_slab * slab);
55
56 /**
57  * Deallocate slab in slab cache
58  *
59  * \param slab  pointer to slab cache
60  * \param objp  pointer to allocated slab
61  */
62 void ddekit_slab_free(struct ddekit_slab * slab, void *objp);
63
64 /**
65  * Setup page cache for all slabs
66  *
67  * \param pages  maximal number of memory pages
68  *
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.
72  *
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
75  * slabs.
76  */
77 void ddekit_slab_setup_page_cache(unsigned pages);
78
79 /**
80  * Destroy slab cache
81  *
82  * \param slab  pointer to slab cache structure
83  */
84 void ddekit_slab_destroy(struct ddekit_slab * slab);
85
86 /**
87  * Initialize slab cache
88  *
89  * \param size          size of cache objects
90  * \param contiguous    make this slab use physically contiguous memory
91  *
92  * \return pointer to new slab cache or 0 on error
93  */
94 struct ddekit_slab * ddekit_slab_init(unsigned size, int contiguous);
95
96
97 /**********************
98  ** Memory allocator **
99  **********************/
100
101 /**
102  * Allocate large memory block
103  *
104  * \param size  block size
105  * \return pointer to new memory block
106  *
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
110  * want.
111  *
112  * Allocated blocks have valid virt->phys mappings and are physically
113  * contiguous.
114  */
115 void *ddekit_large_malloc(int size);
116
117 /**
118  * Free large memory block
119  *
120  * \param p  pointer to memory block
121  */
122 void  ddekit_large_free(void *p);
123
124 /** FIXME
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(
128                 unsigned long size,
129         unsigned long low, unsigned long high,
130         unsigned long alignment, unsigned long boundary
131 );
132
133
134 /*****************************
135  ** Simple memory allocator **
136  *****************************/
137
138 /**
139  * Allocate memory block via simple allocator
140  *
141  * \param size  block size
142  * \return pointer to new memory block
143  *
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.
146  */
147 void *ddekit_simple_malloc(unsigned size);
148
149 /**
150  * Free memory block via simple allocator
151  *
152  * \param p  pointer to memory block
153  */
154 void ddekit_simple_free(void *p);
155
156 EXTERN_C_END