ia64/xen-unstable

view xen/include/xen/xmalloc.h @ 19800:78962f85c562

IOMMU: Add two generic functions to vendor neutral interface

Add 2 generic functions into the vendor neutral iommu interface, The
reason is that from changeset 19732, there is only one global flag
"iommu_enabled" that controls iommu enablement for both vtd and amd
systems, so we need different code paths for vtd and amd iommu systems
if this flag has been turned on. Also, the early checking of
"iommu_enabled" in iommu_setup() is removed to prevent iommu
functionalities from been disabled on amd systems.

Signed-off-by: Wei Wang <wei.wang2@amd.com>
author Keir Fraser <keir.fraser@citrix.com>
date Fri Jun 19 08:41:50 2009 +0100 (2009-06-19)
parents f210a633571c
children
line source
2 #ifndef __XMALLOC_H__
3 #define __XMALLOC_H__
5 /*
6 * Xen malloc/free-style interface.
7 */
9 /* Allocate space for typed object. */
10 #define xmalloc(_type) ((_type *)_xmalloc(sizeof(_type), __alignof__(_type)))
12 /* Allocate space for array of typed objects. */
13 #define xmalloc_array(_type, _num) \
14 ((_type *)_xmalloc_array(sizeof(_type), __alignof__(_type), _num))
16 /* Allocate untyped storage. */
17 #define xmalloc_bytes(_bytes) (_xmalloc(_bytes, SMP_CACHE_BYTES))
19 /* Free any of the above. */
20 extern void xfree(void *);
22 /* Underlying functions */
23 extern void *_xmalloc(unsigned long size, unsigned long align);
24 static inline void *_xmalloc_array(
25 unsigned long size, unsigned long align, unsigned long num)
26 {
27 /* Check for overflow. */
28 if (size && num > UINT_MAX / size)
29 return NULL;
30 return _xmalloc(size * num, align);
31 }
33 /*
34 * Pooled allocator interface.
35 */
37 struct xmem_pool;
39 typedef void *(xmem_pool_get_memory)(unsigned long bytes);
40 typedef void (xmem_pool_put_memory)(void *ptr);
42 /**
43 * xmem_pool_create - create dynamic memory pool
44 * @name: name of the pool
45 * @get_mem: callback function used to expand pool
46 * @put_mem: callback function used to shrink pool
47 * @init_size: inital pool size (in bytes)
48 * @max_size: maximum pool size (in bytes) - set this as 0 for no limit
49 * @grow_size: amount of memory (in bytes) added to pool whenever required
50 *
51 * All size values are rounded up to next page boundary.
52 */
53 struct xmem_pool *xmem_pool_create(
54 const char *name,
55 xmem_pool_get_memory get_mem,
56 xmem_pool_put_memory put_mem,
57 unsigned long init_size,
58 unsigned long max_size,
59 unsigned long grow_size);
61 /**
62 * xmem_pool_destroy - cleanup given pool
63 * @mem_pool: Pool to be destroyed
64 *
65 * Data structures associated with pool are freed.
66 * All memory allocated from pool must be freed before
67 * destorying it.
68 */
69 void xmem_pool_destroy(struct xmem_pool *pool);
71 /**
72 * xmem_pool_alloc - allocate memory from given pool
73 * @size: no. of bytes
74 * @mem_pool: pool to allocate from
75 */
76 void *xmem_pool_alloc(unsigned long size, struct xmem_pool *pool);
78 /**
79 * xmem_pool_maxalloc - xmem_pool_alloc's greater than this size will fail
80 * @mem_pool: pool
81 */
82 int xmem_pool_maxalloc(struct xmem_pool *pool);
84 /**
85 * xmem_pool_maxsize -
86 * @ptr: address of memory to be freed
87 * @mem_pool: pool to free from
88 */
89 void xmem_pool_free(void *ptr, struct xmem_pool *pool);
91 /**
92 * xmem_pool_get_used_size - get memory currently used by given pool
93 *
94 * Used memory includes stored data + metadata + internal fragmentation
95 */
96 unsigned long xmem_pool_get_used_size(struct xmem_pool *pool);
98 /**
99 * xmem_pool_get_total_size - get total memory currently allocated for pool
100 *
101 * This is the total memory currently allocated for this pool which includes
102 * used size + free size.
103 *
104 * (Total - Used) is good indicator of memory efficiency of allocator.
105 */
106 unsigned long xmem_pool_get_total_size(struct xmem_pool *pool);
108 #endif /* __XMALLOC_H__ */