1 /*-
2  * Copyright (c) 2009-2010 Brad Penoff
3  * Copyright (c) 2009-2010 Humaira Kamal
4  * Copyright (c) 2011-2012 Irene Ruengeler
5  * Copyright (c) 2011-2012 Michael Tuexen
6  *
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  * 1. Redistributions of source code must retain the above copyright
13  *    notice, this list of conditions and the following disclaimer.
14  * 2. Redistributions in binary form must reproduce the above copyright
15  *    notice, this list of conditions and the following disclaimer in the
16  *    documentation and/or other materials provided with the distribution.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28  * SUCH DAMAGE.
29  */
30 
31 #ifndef _USER_UMA_H_
32 #define _USER_UMA_H_
33 
34 #define UMA_ZFLAG_FULL		0x40000000	/* Reached uz_maxpages */
35 #define UMA_ALIGN_PTR	(sizeof(void *) - 1)	/* Alignment fit for ptr */
36 
37 /* __Userspace__ All these definitions will change for
38 userspace Universal Memory Allocator (UMA). These are included
39 for reference purposes and to avoid compile errors for the time being.
40 */
41 typedef int (*uma_ctor)(void *mem, int size, void *arg, int flags);
42 typedef void (*uma_dtor)(void *mem, int size, void *arg);
43 typedef int (*uma_init)(void *mem, int size, int flags);
44 typedef void (*uma_fini)(void *mem, int size);
45 typedef struct uma_zone * uma_zone_t;
46 typedef struct uma_keg * uma_keg_t;
47 
48 struct uma_cache {
49 	int stub; /* TODO __Userspace__ */
50 };
51 
52 struct uma_keg {
53 	int stub; /* TODO __Userspace__ */
54 };
55 
56 struct uma_zone {
57 	char		*uz_name;	/* Text name of the zone */
58 	struct mtx	*uz_lock;	/* Lock for the zone (keg's lock) */
59 	uma_keg_t	uz_keg;		/* Our underlying Keg */
60 
61 	LIST_ENTRY(uma_zone)	uz_link;	/* List of all zones in keg */
62 	LIST_HEAD(,uma_bucket)	uz_full_bucket;	/* full buckets */
63 	LIST_HEAD(,uma_bucket)	uz_free_bucket;	/* Buckets for frees */
64 
65 	uma_ctor	uz_ctor;	/* Constructor for each allocation */
66 	uma_dtor	uz_dtor;	/* Destructor */
67 	uma_init	uz_init;	/* Initializer for each item */
68 	uma_fini	uz_fini;	/* Discards memory */
69 
70 	u_int64_t	uz_allocs;	/* Total number of allocations */
71 	u_int64_t	uz_frees;	/* Total number of frees */
72 	u_int64_t	uz_fails;	/* Total number of alloc failures */
73 	uint16_t	uz_fills;	/* Outstanding bucket fills */
74 	uint16_t	uz_count;	/* Highest value ub_ptr can have */
75 
76 	/*
77 	 * This HAS to be the last item because we adjust the zone size
78 	 * based on NCPU and then allocate the space for the zones.
79 	 */
80 	struct uma_cache	uz_cpu[1];	/* Per cpu caches */
81 };
82 
83 /* Prototype */
84 uma_zone_t
85 uma_zcreate(char *name, size_t size, uma_ctor ctor, uma_dtor dtor,
86 	    uma_init uminit, uma_fini fini, int align, uint32_t flags);
87 
88 
89 #define uma_zone_set_max(zone, number) /* stub TODO __Userspace__ */
90 
91 uma_zone_t
uma_zcreate(char * name,size_t size,uma_ctor ctor,uma_dtor dtor,uma_init uminit,uma_fini fini,int align,uint32_t flags)92 uma_zcreate(char *name, size_t size, uma_ctor ctor, uma_dtor dtor,
93 	    uma_init uminit, uma_fini fini, int align, uint32_t flags) {
94 	return NULL; /* stub TODO __Userspace__. Also place implementation in a separate .c file */
95 }
96 #endif
97