Remove building with NOCRYPTO option
[minix.git] / minix / include / ddekit / memory.h
blob5f18d5f48774328559744593ef4b8cda553bb0fa
1 /*-
2 * Copyright (c) 2006 Thomas Friebel <tf13@os.inf.tu-dresden.de>
3 * Copyright (c) 2006 Christian Helmuth <ch12@os.inf.tu-dresden.de>
4 * Copyright (c) 2010 Dirk Vogt <dvogt@few.vu.nl>.
5 * All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
16 * distribution.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
21 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
22 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
23 * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
24 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
26 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
28 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE.
31 #ifndef _DDEKIT_MEMORY_H
32 #define _DDEKIT_MEMORY_H
34 #include <ddekit/ddekit.h>
36 /*******************
37 ** Slab facility **
38 *******************/
40 struct ddekit_slab;
42 /* Store user pointer in slab cache */
43 void ddekit_slab_set_data(struct ddekit_slab * slab, void *data);
45 /* Read user pointer from slab cache */
46 void *ddekit_slab_get_data(struct ddekit_slab * slab);
48 /* Allocate slab in slab cache */
49 void *ddekit_slab_alloc(struct ddekit_slab * slab);
51 /* Allocate slab in slab cache */
52 void ddekit_slab_free(struct ddekit_slab * slab, void *objp);
55 * Setup page cache for all slabs
57 * pages: maximal number of memory pages
59 * If 'pages' is too low, memory pages may be given back to the memory server
60 * (dm_phys) and just to be allocated again later. This hits performance (but
61 * saves memory). Increase 'pages' to avoid this thrashing-like effect.
63 * If the maximal number of unused pages is exceeded, subsequent deallocation
64 * will be freed at the memory server. This page cache caches pages from all
65 * slabs.
67 void ddekit_slab_setup_page_cache(unsigned pages);
70 * Destroy slab cache
72 * slab: pointer to slab cache structure
74 void ddekit_slab_destroy(struct ddekit_slab * slab);
76 /**
77 * Initialize slab cache
79 * \param size size of cache objects
80 * \param contiguous make this slab use physically contiguous memory
82 * \return pointer to new slab cache or 0 on error
84 struct ddekit_slab * ddekit_slab_init(unsigned size, int contiguous);
87 /**********************
88 ** Memory allocator **
89 **********************/
92 * Allocate large memory block
94 * \param size block size
95 * \return pointer to new memory block
97 * Allocations via this allocator may be slow (because memory servers are
98 * involved) and should be used only for large (i.e., > page size) blocks. If
99 * allocations/deallocations are relatively dynamic this may not be what you
100 * want.
102 * Allocated blocks have valid virt->phys mappings and are physically
103 * contiguous.
105 void *ddekit_large_malloc(int size);
108 * Free large memory block
110 * \param p pointer to memory block
112 void ddekit_large_free(void *p);
114 /** FIXME
115 * contig_malloc() is the lowest-level allocator interface one could implement.
116 * we should consider to provide vmalloc() too. */
117 void *ddekit_contig_malloc(unsigned long size, unsigned long low,
118 unsigned long high, unsigned long alignment, unsigned long boundary);
121 /*****************************
122 ** Simple memory allocator **
123 *****************************/
126 * Allocate memory block via simple allocator
128 * \param size block size
129 * \return pointer to new memory block
131 * The blocks allocated via this allocator CANNOT be used for DMA or other
132 * device operations, i.e., there exists no virt->phys mapping.
134 void *ddekit_simple_malloc(unsigned size);
137 * Free memory block via simple allocator
139 * \param p pointer to memory block
141 void ddekit_simple_free(void *p);
143 #endif