Whamcloud - gitweb
b=17167 libcfs: ensure all libcfs exported symbols to have cfs_ prefix
[fs/lustre-release.git] / libcfs / include / libcfs / winnt / winnt-mem.h
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  * GPL HEADER START
5  *
6  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License version 2 only,
10  * as published by the Free Software Foundation.
11  *
12  * This program is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * General Public License version 2 for more details (a copy is included
16  * in the LICENSE file that accompanied this code).
17  *
18  * You should have received a copy of the GNU General Public License
19  * version 2 along with this program; If not, see
20  * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
21  *
22  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23  * CA 95054 USA or visit www.sun.com if you need additional information or
24  * have any questions.
25  *
26  * GPL HEADER END
27  */
28 /*
29  * Copyright  2008 Sun Microsystems, Inc. All rights reserved
30  * Use is subject to license terms.
31  */
32 /*
33  * This file is part of Lustre, http://www.lustre.org/
34  * Lustre is a trademark of Sun Microsystems, Inc.
35  *
36  * libcfs/include/libcfs/winnt/winnt-mem.h
37  *
38  * Basic library routines of memory manipulation routines.
39  */
40
41 #ifndef __LIBCFS_WINNT_CFS_MEM_H__
42 #define __LIBCFS_WINNT_CFS_MEM_H__
43
44 #ifndef __LIBCFS_LIBCFS_H__
45 #error Do not #include this file directly. #include <libcfs/libcfs.h> instead
46 #endif
47
48 #include <libcfs/winnt/portals_utils.h>
49
50 #ifdef __KERNEL__
51
52 typedef struct cfs_mem_cache cfs_mem_cache_t;
53
54 /*
55  * page definitions
56  */
57
58 #define CFS_PAGE_SIZE                   PAGE_SIZE
59 #define CFS_PAGE_SHIFT                  PAGE_SHIFT
60 #define CFS_PAGE_MASK                   (~(PAGE_SIZE - 1))
61
62 typedef struct cfs_page {
63     void *          addr;
64     cfs_atomic_t    count;
65     void *          private;
66     void *          mapping;
67     __u32           index;
68     __u32           flags;
69 } cfs_page_t;
70
71 #define page cfs_page
72
73 #ifndef page_private
74 #define page_private(page) ((page)->private)
75 #define set_page_private(page, v) ((page)->private = (v))
76 #endif
77
78 #define page_count(page) (0)
79
80 #define PG_locked                0      /* Page is locked. Don't touch. */
81 #define PG_error                 1
82 #define PG_referenced            2
83 #define PG_uptodate              3
84
85 #define PG_dirty                 4
86 #define PG_lru                   5
87 #define PG_active                6
88 #define PG_slab                  7      /* slab debug (Suparna wants this) */
89
90 #define PG_owner_priv_1          8      /* Owner use. If pagecache, fs may use*/
91 #define PG_arch_1                9
92 #define PG_reserved             10
93 #define PG_private              11      /* If pagecache, has fs-private data */
94
95 #define PG_writeback            12      /* Page is under writeback */
96 #define PG_compound             14      /* Part of a compound page */
97 #define PG_swapcache            15      /* Swap page: swp_entry_t in private */
98
99 #define PG_mappedtodisk         16      /* Has blocks allocated on-disk */
100 #define PG_reclaim              17      /* To be reclaimed asap */
101 #define PG_buddy                19      /* Page is free, on buddy lists */
102
103 #define PG_virt         31  /* addr is not */
104
105 #ifndef arch_set_page_uptodate
106 #define arch_set_page_uptodate(page)
107 #endif
108
109 /* Make it prettier to test the above... */
110 #define UnlockPage(page)        unlock_page(page)
111 #define Page_Uptodate(page)     cfs_test_bit(PG_uptodate, &(page)->flags)
112 #define SetPageUptodate(page) \
113         do {                                                            \
114                 arch_set_page_uptodate(page);                           \
115                 cfs_set_bit(PG_uptodate, &(page)->flags);               \
116         } while (0)
117 #define ClearPageUptodate(page) cfs_clear_bit(PG_uptodate, &(page)->flags)
118 #define PageDirty(page)         cfs_test_bit(PG_dirty, &(page)->flags)
119 #define SetPageDirty(page)      cfs_set_bit(PG_dirty, &(page)->flags)
120 #define ClearPageDirty(page)    cfs_clear_bit(PG_dirty, &(page)->flags)
121 #define PageLocked(page)        cfs_test_bit(PG_locked, &(page)->flags)
122 #define LockPage(page)          cfs_set_bit(PG_locked, &(page)->flags)
123 #define TryLockPage(page)       cfs_test_and_set_bit(PG_locked, &(page)->flags)
124 #define PageChecked(page)       cfs_test_bit(PG_checked, &(page)->flags)
125 #define SetPageChecked(page)    cfs_set_bit(PG_checked, &(page)->flags)
126 #define ClearPageChecked(page)  cfs_clear_bit(PG_checked, &(page)->flags)
127 #define PageLaunder(page)       cfs_test_bit(PG_launder, &(page)->flags)
128 #define SetPageLaunder(page)    cfs_set_bit(PG_launder, &(page)->flags)
129 #define ClearPageLaunder(page)  cfs_clear_bit(PG_launder, &(page)->flags)
130 #define ClearPageArch1(page)    cfs_clear_bit(PG_arch_1, &(page)->flags)
131
132 #define PageError(page)         cfs_test_bit(PG_error, &(page)->flags)
133 #define SetPageError(page)      cfs_set_bit(PG_error, &(page)->flags)
134 #define ClearPageError(page)    cfs_clear_bit(PG_error, &(page)->flags)
135 #define PageReferenced(page)    cfs_test_bit(PG_referenced, &(page)->flags)
136 #define SetPageReferenced(page) cfs_set_bit(PG_referenced, &(page)->flags)
137 #define ClearPageReferenced(page) cfs_clear_bit(PG_referenced, &(page)->flags)
138
139 #define PageActive(page)        cfs_test_bit(PG_active, &(page)->flags)
140 #define SetPageActive(page)     cfs_set_bit(PG_active, &(page)->flags)
141 #define ClearPageActive(page)   cfs_clear_bit(PG_active, &(page)->flags)
142
143 #define PageWriteback(page)     cfs_test_bit(PG_writeback, &(page)->flags)
144 #define TestSetPageWriteback(page) cfs_test_and_set_bit(PG_writeback,   \
145                                                         &(page)->flags)
146 #define TestClearPageWriteback(page) cfs_test_and_clear_bit(PG_writeback, \
147                                                         &(page)->flags)
148
149 #define __GFP_FS    (1)
150 #define GFP_KERNEL  (2)
151 #define GFP_ATOMIC  (4)
152
153 cfs_page_t *cfs_alloc_page(int flags);
154 void cfs_free_page(cfs_page_t *pg);
155 void cfs_release_page(cfs_page_t *pg);
156 cfs_page_t * virt_to_page(void * addr);
157 cfs_page_t *cfs_alloc_pages(unsigned int flags, unsigned int order);
158 void __cfs_free_pages(cfs_page_t *page, unsigned int order);
159 int cfs_mem_is_in_cache(const void *addr, const cfs_mem_cache_t *kmem);
160
161 #define page_cache_get(a) do {} while (0)
162 #define page_cache_release(a) do {} while (0)
163
164 static inline void *cfs_page_address(cfs_page_t *page)
165 {
166     return page->addr;
167 }
168
169 static inline void *cfs_kmap(cfs_page_t *page)
170 {
171     return page->addr;
172 }
173
174 static inline void cfs_kunmap(cfs_page_t *page)
175 {
176     return;
177 }
178
179 static inline void cfs_get_page(cfs_page_t *page)
180 {
181     cfs_atomic_inc(&page->count);
182 }
183
184 static inline void cfs_put_page(cfs_page_t *page)
185 {
186     cfs_atomic_dec(&page->count);
187 }
188
189 static inline int cfs_page_count(cfs_page_t *page)
190 {
191     return cfs_atomic_read(&page->count);
192 }
193
194 #define cfs_page_index(p)       ((p)->index)
195
196 /*
197  * Memory allocator
198  */
199
200 #define CFS_ALLOC_ATOMIC_TRY    (0)
201 extern void *cfs_alloc(size_t nr_bytes, u_int32_t flags);
202 extern void  cfs_free(void *addr);
203
204 #define kmalloc cfs_alloc
205
206 extern void *cfs_alloc_large(size_t nr_bytes);
207 extern void  cfs_free_large(void *addr);
208
209 /*
210  * SLAB allocator
211  */
212
213 #define CFS_SLAB_HWCACHE_ALIGN          0
214
215 /* The cache name is limited to 20 chars */
216
217 struct cfs_mem_cache {
218     char                    name[20];
219     ulong_ptr_t             flags;
220     NPAGED_LOOKASIDE_LIST   npll;
221 };
222
223
224 extern cfs_mem_cache_t *cfs_mem_cache_create (const char *, size_t, size_t,
225                                               unsigned long);
226 extern int cfs_mem_cache_destroy (cfs_mem_cache_t * );
227 extern void *cfs_mem_cache_alloc (cfs_mem_cache_t *, int);
228 extern void cfs_mem_cache_free (cfs_mem_cache_t *, void *);
229
230 /*
231  * shrinker 
232  */
233 typedef int (*shrink_callback)(int nr_to_scan, gfp_t gfp_mask);
234 struct cfs_shrinker {
235         shrink_callback cb;
236         int seeks;      /* seeks to recreate an obj */
237
238         /* These are for internal use */
239         cfs_list_t list;
240         long nr;        /* objs pending delete */
241 };
242
243 struct cfs_shrinker *cfs_set_shrinker(int seeks, shrink_callback cb);
244 void cfs_remove_shrinker(struct cfs_shrinker *s);
245
246 int start_shrinker_timer();
247 void stop_shrinker_timer();
248
249 /*
250  * Page allocator slabs 
251  */
252
253 extern cfs_mem_cache_t *cfs_page_t_slab;
254 extern cfs_mem_cache_t *cfs_page_p_slab;
255
256
257 #define CFS_DECL_MMSPACE
258 #define CFS_MMSPACE_OPEN    do {} while(0)
259 #define CFS_MMSPACE_CLOSE   do {} while(0)
260
261
262 #define cfs_mb()     do {} while(0)
263 #define rmb()        cfs_mb()
264 #define wmb()        cfs_mb()
265
266 /*
267  * MM defintions from (linux/mm.h)
268  */
269
270 #define CFS_DEFAULT_SEEKS 2 /* shrink seek */
271
272 #else  /* !__KERNEL__ */
273
274 #include "../user-mem.h"
275
276 /* page alignmed buffer allocation */
277 void* pgalloc(size_t factor);
278 void  pgfree(void * page);
279
280 #endif /* __KERNEL__ */
281
282 #endif /* __WINNT_CFS_MEM_H__ */