Whamcloud - gitweb
c5cbfa0faa745196d6112db768a4c12249d8199e
[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 #ifdef __KERNEL__
49
50 #define CFS_PAGE_SIZE                   PAGE_SIZE
51 #define CFS_PAGE_SHIFT                  PAGE_SHIFT
52 #define CFS_PAGE_MASK                   (~(PAGE_SIZE - 1))
53
54 typedef struct cfs_page {
55     void *      addr;
56     atomic_t    count;
57 } cfs_page_t;
58
59
60 cfs_page_t *cfs_alloc_page(int flags);
61 void cfs_free_page(cfs_page_t *pg);
62
63 static inline void *cfs_page_address(cfs_page_t *page)
64 {
65     return page->addr;
66 }
67
68 static inline void *cfs_kmap(cfs_page_t *page)
69 {
70     return page->addr;
71 }
72
73 static inline void cfs_kunmap(cfs_page_t *page)
74 {
75     return;
76 }
77
78 static inline void cfs_get_page(cfs_page_t *page)
79 {
80     atomic_inc(&page->count);
81 }
82
83 static inline void cfs_put_page(cfs_page_t *page)
84 {
85     atomic_dec(&page->count);
86 }
87
88 static inline int cfs_page_count(cfs_page_t *page)
89 {
90     return atomic_read(&page->count);
91 }
92
93 /*
94  * Memory allocator
95  */
96
97 #define CFS_ALLOC_ATOMIC_TRY    (0)
98
99 extern void *cfs_alloc(size_t nr_bytes, u_int32_t flags);
100 extern void  cfs_free(void *addr);
101
102 extern void *cfs_alloc_large(size_t nr_bytes);
103 extern void  cfs_free_large(void *addr);
104
105 /*
106  * SLAB allocator
107  */
108
109 #define SLAB_HWCACHE_ALIGN              0
110
111 /* The cache name is limited to 20 chars */
112
113 typedef struct cfs_mem_cache {
114
115     char                    name[20];
116     ulong_ptr           flags;
117     NPAGED_LOOKASIDE_LIST   npll;
118
119 } cfs_mem_cache_t;
120
121
122 extern cfs_mem_cache_t * cfs_mem_cache_create (const char *, size_t, size_t, ulong_ptr);
123 extern int cfs_mem_cache_destroy ( cfs_mem_cache_t * );
124 extern void *cfs_mem_cache_alloc ( cfs_mem_cache_t *, int);
125 extern void cfs_mem_cache_free ( cfs_mem_cache_t *, void *);
126
127
128 /*
129  * Page allocator slabs 
130  */
131
132 extern cfs_mem_cache_t *cfs_page_t_slab;
133 extern cfs_mem_cache_t *cfs_page_p_slab;
134
135
136 #define CFS_DECL_MMSPACE
137 #define CFS_MMSPACE_OPEN    do {} while(0)
138 #define CFS_MMSPACE_CLOSE   do {} while(0)
139
140
141 #define mb()    do {} while(0)
142 #define rmb()   mb()
143 #define wmb()   mb()
144
145
146 /* __KERNEL__ */
147 #endif
148
149 #endif /* __WINNT_CFS_MEM_H__ */