Whamcloud - gitweb
Branch HEAD
[fs/lustre-release.git] / lnet / include / libcfs / winnt / winnt-mem.h
1 /* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=4:tabstop=4:
3  *
4  *  Copyright (C) 2001 Cluster File Systems, Inc. <braam@clusterfs.com>
5  *
6  *   This file is part of Lustre, http://www.lustre.org.
7  *
8  *   Lustre is free software; you can redistribute it and/or
9  *   modify it under the terms of version 2 of the GNU General Public
10  *   License as published by the Free Software Foundation.
11  *
12  *   Lustre is distributed in the hope that it will be useful,
13  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  *   GNU General Public License for more details.
16  *
17  *   You should have received a copy of the GNU General Public License
18  *   along with Lustre; if not, write to the Free Software
19  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20  *
21  * Basic library routines of memory manipulation routines .
22  *
23  */
24
25 #ifndef __LIBCFS_WINNT_CFS_MEM_H__
26 #define __LIBCFS_WINNT_CFS_MEM_H__
27
28 #ifndef __LIBCFS_LIBCFS_H__
29 #error Do not #include this file directly. #include <libcfs/libcfs.h> instead
30 #endif
31
32 #ifdef __KERNEL__
33
34 #define CFS_PAGE_SIZE                   PAGE_SIZE
35 #define CFS_PAGE_SHIFT                  PAGE_SHIFT
36 #define CFS_PAGE_MASK                   (~(PAGE_SIZE - 1))
37
38 typedef struct cfs_page {
39     void *      addr;
40     atomic_t    count;
41 } cfs_page_t;
42
43
44 cfs_page_t *cfs_alloc_page(int flags);
45 void cfs_free_page(cfs_page_t *pg);
46
47 static inline void *cfs_page_address(cfs_page_t *page)
48 {
49     return page->addr;
50 }
51
52 static inline void *cfs_kmap(cfs_page_t *page)
53 {
54     return page->addr;
55 }
56
57 static inline void cfs_kunmap(cfs_page_t *page)
58 {
59     return;
60 }
61
62 static inline void cfs_get_page(cfs_page_t *page)
63 {
64     atomic_inc(&page->count);
65 }
66
67 static inline void cfs_put_page(cfs_page_t *page)
68 {
69     atomic_dec(&page->count);
70 }
71
72 static inline int cfs_page_count(cfs_page_t *page)
73 {
74     return atomic_read(&page->count);
75 }
76
77 /*
78  * Memory allocator
79  */
80
81 #define CFS_ALLOC_ATOMIC_TRY    (0)
82
83 extern void *cfs_alloc(size_t nr_bytes, u_int32_t flags);
84 extern void  cfs_free(void *addr);
85
86 extern void *cfs_alloc_large(size_t nr_bytes);
87 extern void  cfs_free_large(void *addr);
88
89 /*
90  * SLAB allocator
91  */
92
93 #define SLAB_HWCACHE_ALIGN              0
94
95 /* The cache name is limited to 20 chars */
96
97 typedef struct cfs_mem_cache {
98
99     char                    name[20];
100     ulong_ptr           flags;
101     NPAGED_LOOKASIDE_LIST   npll;
102
103 } cfs_mem_cache_t;
104
105
106 extern cfs_mem_cache_t * cfs_mem_cache_create (const char *, size_t, size_t, ulong_ptr);
107 extern int cfs_mem_cache_destroy ( cfs_mem_cache_t * );
108 extern void *cfs_mem_cache_alloc ( cfs_mem_cache_t *, int);
109 extern void cfs_mem_cache_free ( cfs_mem_cache_t *, void *);
110
111
112 /*
113  * Page allocator slabs 
114  */
115
116 extern cfs_mem_cache_t *cfs_page_t_slab;
117 extern cfs_mem_cache_t *cfs_page_p_slab;
118
119
120 #define CFS_DECL_MMSPACE
121 #define CFS_MMSPACE_OPEN    do {} while(0)
122 #define CFS_MMSPACE_CLOSE   do {} while(0)
123
124
125 #define mb()    do {} while(0)
126 #define rmb()   mb()
127 #define wmb()   mb()
128
129
130 /* __KERNEL__ */
131 #endif
132
133 #endif /* __WINNT_CFS_MEM_H__ */